Skip to main content

Posts

Showing posts from October, 2012

JSF2 - h:dataTable Demo using HashMap

 The data table component in JSF2 is used for displaying database table, array list, hash map, etc.., into tabular format. In JSP, if you want to display a table record in tabular format, we need to create a html table template after that we need to iterate the result set object. Here that is not necessary, because the h:dataTable automatically create a table template based on your inputs as well it have lot of useful attributes for specifying style class for HTML tags like table, th, tr and td.  This is very simple use case of h:dataTable. Here I am using HashMap, Inside the hash map I have all country name as key and corresponding capital name as value. Now I am going to display that hash map into tabular format using h:dataTable component.   The rowClasses, columnClasses, header and footer classes are very useful attributes used for define your own css classes into table

JSF2 - Number Converter Demo

 The number converter in JSF2 is used to convert a component data into java.lang.Number format. Additionally it have lot of attributes for customizing number format. The sample usage is given here.  The important one is, the numberConverter binding component managed bean property should be a primitive type or has a type of java.lang.Number only. Here the "number" type is java.lang.Number. This is another usage of number converter.  THe result of the above code is something like $22.50. The sample application is available in Github .

JSF2 - Date Time Converter Demo

 The date time converter in JSF2 is used to convert a text value into java.util.Date value. The date time converter has several attributes, that is used to specify the format and type of data. The most used formats are locale, timeStyle, for, timeZone etc.., The example usage is given here. Please enter a date in dd/mm/yyyy format  The sample application is available in Github .

JSF2-Integer Converter Demo

 The Integer converter in JSF2 is used to convert a text value into integer value. This is my managed bean, here I have declared one Integer variable and I have created accessor method for that variable. package com.pointerunits; import javax.faces.bean.ManagedBean; import javax.faces.bean.SessionScoped; @ManagedBean @SessionScoped public class Converter { private Integer intNumber; public Converter() { } public Integer getIntNumber() { return intNumber; } public void setIntNumber(Integer intNumber) { this.intNumber = intNumber; } }  This is my xhtml page, Here I have created one input text filed and converted that field value into integer using integer converter. If converter can't able to convert then it't will display the error message.  You can download an entire application from github .