Skip to main content

Posts

Showing posts with the label JSF

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...

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 .

Converters in JSF 2

 Converters in JSF2 are used to easily convert a value from one data type to other. The following inbuilt converters are available in JSF2. Converter Name Converter Class Byte Converter javax.faces.convert.ByteConverter Short Converter javax.faces.convert.ShortConverter Character Converter javax.faces.convert.CharacterConverter Boolean Converter javax.faces.convert.BooleanConverter Integer Converter javax.faces.convert.IntegerConverter Float Converter javax.faces.convert.FloatConverter Double Converter javax.faces.convert.DoubleConverter Long Converter javax.faces.convert.LongConverter Big Integer Converter javax.faces.convert.BigIntegerConverter Big Decimal Converter javax.faces.convert.BigDecimalConverter Date Time Converter javax.faces.convert.DateTimeConverter Number Converter javax.faces.convert.NumberConverter Enum Converter...

Guessing Game Implementation using JSF

 In a typical Java Server Faces application each page connect to a managed bean, that have properties and methods that are associated with the components. This Guessing Game application consists of one managed bean and two views. All views are using same bean.  The following are requirements for this application. 1. User must enter a number from 0 to 10. 2. Maximum number of attempt is 5. 3. If user guess a correct number with in 5 attempts, the success message is displayed to the user otherwise the failure message is displayed.  Ok let's create a managed bean for implementing above requirements. package com.pointerunits; import java.io.IOException; import java.util.Random; import javax.faces.bean.ManagedBean; import javax.faces.bean.SessionScoped; import javax.faces.context.FacesContext; @ManagedBean @SessionScoped public class GuessingGame { private int randomNumber; private int userNumber; private int minimum; private int maximum; private int allowab...

Simple login application using JSF

1.       Login page . index.jsp. <%@ page language = "java" contentType = "text/html; charset=ISO-8859-1"     pageEncoding = "ISO-8859-1" %> <%@ taglib prefix = "f" uri = "http://java.sun.com/jsf/core" %> <%@ taglib prefix = "h" uri = "http://java.sun.com/jsf/html" %> <! DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd" > < html > < head > < meta http-equiv = "Content-Type" content = "text/html; charset=ISO-8859-1" > < title > JSF Login Application </ title > </ head > < body >       < f:view >             < h:form >                   < table style =" width : 80% ; border : 1px solid black ; margin-top : 2px ; margin-left : 10% ; margin-rig...