Showing posts with label JSF Core Tag Reference. Show all posts
Showing posts with label JSF Core Tag Reference. Show all posts

JSF actionListener Tag

This tag is used to add a action listener to the component associated with the enclosing tag. When user does an event on the component then this action takes place. The class where this action is defined implements ActionListener interface. In this example this class is "MyBean.java" in roseindia package. Within this class a method processAction() is written, where we write our logic of action.

Code Description :

<%@ page contentType="text/html" %>
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>











MyBean.java :

package roseindia;

import java.util.*;
import javax.swing.*;
import javax.faces.event.*;

public class MyBean implements ActionListener,ValueChangeListener{
String som = "";
private Date today = new Date();
public void processAction(ActionEvent e){
JOptionPane.showMessageDialog(null,"Hi");
}


public void processValueChange(ValueChangeEvent ce){
JOptionPane.showMessageDialog(null, ce.getSource());
}

public String getSom(){
return som;
}

public void setSom(String som){
this.som = som;
}

public Date getToday(){
return today;
}

public void setToday(Date today) {
this.today = today;
}
}

Rendered Output : This is the first page that appears to the user. There is one form button which when clicked renders a message dialog as it is shown in the second picture below.

Html Source Code :







This tag contains one attribute :

type : This attribute is used to specify the fully qualified name of the class which has implemented ActionListener interface and implemented processAction() method.

read more “JSF actionListener Tag”

JSF attributeTag

This tag is used to add attribute to the nearest parent component. This is name/value pair where name takes the attribute name which will be set to the component and value takes the value of the attribute. In this example, command button tag is assigned only one attribute "id", then attribute tag is used to assign more attributes and its values. For example, instead of specifying "value" attribute and its value "Click" ( i.e. value="Click") in commandButton tag parallel to "id" attribute, this has been associated to the component using attribute tag.

Code Description :

<%@ page contentType="text/html" %>
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>












Rendered Output :

Html Source Code :









This tag contains two attributes :

name : This is the required attribute which is used to specify the name of the attribute of the nearest parent component.
value :
This is the required attribute which is used to specify the value of the attribute specified in name attribute of this tag.

read more “JSF attributeTag”

JSF convertDateTime Tag

This tag is useful converting date and time according to your format. It supports many attributes which can give different styles of presenting date and time like locale attribute formats the date and time according to locale and dateStyle, timeStyle determines how date and time is to be formatted. Date and time can be formatted according to the time zone by setting the timeZone attribute. We have made a simple program to illustrate this tag.

Code Description :

<%@ page contentType="text/html" %>
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>











Rendered Output :

Html Source Code :




5/14/07 12:55:42 PM


This tag contains some attributes:

dateStyle : This is used to set the style of date to be presented to the page. This attribute is applied only if the type attribute is "date" or "both". This attribute can take some values like :

  1. default May 14, 2007 2:35:45 PM ( Default Value)
  2. short 5/14/07 12:55:42 PM
  3. medium May 14, 2007 2:42:36 PM
  4. long May 14, 2007 2:41:08 PM
  5. full Monday, May 14, 2007 2:39:56 PM

timeStyle : This is used to set the style of time to be presented to the page. This attribute is applied only if the type attribute is "time" or "both". It also can take values default ( Default Value), short, medium, long, full.
locale : This is used to specify the name of the locale for which we have to format the date and time.
pattern :
This is used to set the formatting pattern as defined in java.text.SimpleDateFormat. This is used to determine how the date and time will be formatted.
timeZone :
This attribute is used to set the time zone for which the date and time is to be formatted. Its default time zone is GMT time zone.
type :
It is used to specify whether date, time or both is to be formatted. Its valid values are "date" (dafault), "time" and "both".

read more “JSF convertDateTime Tag”

JSF converter Tag

This tag is used to register the converter instance on the enclosing component. Many times it is required to convert the input to the appropriate type. In this case this tag can be useful. It takes one required attribute "converterId". In this attribute we specify the name of backing bean class which implements Converter interface. You have to maintain the faces-config file where converter-id and converter-class is specified within the converter element.

Code Description :

<%@ page contentType="text/html" %>
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>






















Rendered Output : This is the first output that comes in front of the user.

When user inputs wrong input that can not be converted to the appropriate type then the conversion error occurs, like below :

Html Source Code :
















This tag contains one attribute :

converterId : This is the required attribute and is used to specify the ID of the converter class which is used in the conversion process (in the case of custom conversion).

read more “JSF converter Tag”

JSF convertNumber Tag

This tag is used to register the NumberConverter instance on the enclosing component. This class is responsible to convert String to java.util.Number object and vice-versa.

Code Description :

<%@ page contentType="text/html" %>
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>






















Rendered Output : This is the first output that comes in front of the user.

When user inputs wrong input that does not start with the $ sign then error occurs, like below :

Html Source Code :

















This tag contains some attributes:

currencyCode : In this attribute ISO 4217 currency code is set that will be applied when converting currency values.
currencySymbol : This sets the currency symbol that will be applied when formatting currency values.
groupingUsed :
This is the boolean attribute and is used to specify whether the output will contain grouping seperators. Its default value is "true".
integerOnly :
This is the boolean attribute and is used to specify whether only the integer part will be parsed.Its default value is "false".
locale :
This is used to specify the name of the locale for which we have to format the number.
maxFractionDigits :
It is used to specify the maximum no. of digits in the fractional part that will be formated.
maxIntegerDigits :
It is used to specify the maximum no. of digits in the integer part that will be formated.
minFractionDigits :
It is used to specify the minimum no. of digits in the fractional part that will be formated.
minIntegerDigits :
It is used to specify the minimum no. of digits in the integer part that will be formated.
pattern :
This is used to set the formatting pattern.
type :
It is used to specify the type of formatting. Its valid values are "number" "currency" "percentage". Its default value is "number".

read more “JSF convertNumber Tag”

JSF facet Tag

This tag is used to add a facet to the component means this tag is used to add its child as a facet of the closest parent component. With the help of this tag we can add header and footer facet to the container component like panelGroup.

Code Description :

<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
























Rendered Output :

Html Source Code :






























header facet
footer facet
First Name
Last Name
Address




This tag contains one attribute :

name : This is the required attribute and is used to set the name of the facet. "header" and "footer" values can be used for this attribute.

read more “JSF facet Tag”

JSF loadBundle Tag

This tag is used to load the recourse bundle and store it as a map in the request scope. This allows you to access the message in your JSF. There are two attributes for this tag "basename" and "var". "basename" is the base name where the bundle is present and "var" represents the name by which the we will refer this bundle in our jsf page.

Code Description :

<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>









Resource Bundle file(RB.properties in WEB_INF/classes folder):

greeting_text=Welcome In Roseindia JSF Tutorial

Rendered Output :

Html Source Code :





Welcome In Roseindia JSF Tutorial




Attributes that this tag uses are given below :

basename : It is used to provide the name of the base of the resource bundle which is to be loaded and used in our pages.
var :
This is used to give the name of the attribute in request scope, where the bundle is stored as a map, to access the bundle by this name.

read more “JSF loadBundle Tag”

JSF param Tag

This tag is used to set the parameter to the enclosing component. This tag is helpful in the case of creating the compound message. Its value attribute can be set using EL to get the current value from the backing bean property. Suppose you are using outputFormat tag to create compound message where these param values can be used.

Code Description : In the code below {0}and {1}are replaced by the param values specified within outputFormat tag. param values are being taken from properties of backing bean "MessageBean".

<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>












Output Rendered :

Html Source Code :




Hi,Alex. This is to inform you,123456 is your password .



This tag contains some attributes that are explained below :

binding : This attribute takes value binding expression to link component to the banking bean property.
id :
This is used to uniquely identify the component.
name :
This is used to set the name of the parameter.
value :
This is used to set the value of the parameter.

read more “JSF param Tag”

JSF selectItem Tag

This tag is used to add a child component to the component associated with the enclosing tag. In this section you will learn about the selectItem tag. It can be used with any select tag of JSF html tag library. It renders "option" element when converted to html. In the example below selectItem tag has been used within selectManyListbox tag. So these are the child components of List Box component and these child components provides options for the List Box component.

Code Description :

<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>



















Rendered Output :

Html Source Code :





Select windows to open






This tag contains some attributes :

id : This is used to uniquely identify the table component. This must be unique within the closest parent component.
binding : It is a value binding expression that is used to link component to a property in a backing bean.
itemLabel : This is used to set the label for the option rendered by this tag.
itemValue : This is used to set the value for the option rendered by this tag. This value is used at server when option is selected.
value : This is the value binding expression that indicates to the selectItem instance which contains the information about the option.
itemDescription : It is used to describe something about this option for your own purpose.
itemDisabled : This is a boolean attribute and is used to make the option enable or disable when it is set to "true" and "false" respectively. Its default value is "false".
read more “JSF selectItem Tag”

JSF selectItems Tag

This tag is used to add a set of items to the nearest enclosing parent (select one or select many) component. This tag can be used to get the list of choices from the list of objects from backing bean. So instead of writing many selectItem tag for choices, you can use selectItems tag to get the options list in the form of list of objects from backing bean.

Code Description :

<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>














Backing Bean (SItemsBean.java) : In the code below, we have taken array list of SelectItem objects. It has 5 constructors. One of its constructor accepts value as Object and label as String parameter while the another one accepts value as Object, label as String, description as String disabled as boolean parameters. description parameter is used for own purpose to describe something and disabled is used to make the option enabled or disabled by setting it "true" and "false" respectively. You can use them according to the need. You can understand it better by the code given below :

import javax.faces.model.SelectItem;
import java.util.*;

public class SItemsBean
{
private List options;
public SItemsBean()
{
options = new ArrayList();
SelectItem option = new SelectItem("ch1", "choice1", "This bean is for selectItems tag", true);
options.add(option);
option = new SelectItem("ch2", "choice2");
options.add(option);
option = new SelectItem("ch3", "choice3");
options.add(option);
option = new SelectItem("ch4", "choice4");
options.add(option);
option = new SelectItem("ch5", "choice5);
options.add(option);
}

public void setOptions(List opt)
{
options = opt;
}

public List getOptions()
{
return options;
}
}

Rendered Output :

Html Source Code :




Select choices given below :





This tag contains some attributes :

id : This is used to uniquely identify the table component. This must be unique within the closest parent component.
binding : It is a value binding expression that is used to link component to a property in a backing bean.
value : This is the value binding expression that indicates to the list or array of selectItem instances which contains the information about the option.
read more “JSF selectItems Tag”

JSF subview Tag

This tag is used to create the sub-view of the view. It contains all JSF tags in a page that is included in another JSP page. It acts as a naming container so that the components inside it can be made unique. This naming container contains JSF tags on a nested page by or the tag which includes the page dynamically. To include another JSP or JSF page, using or , we must use tag around it so that JSF process the included file properly. subview.jsp is the main page where subview tag is used to include next.jsp page.

Code Description :

subview.jsp :

<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>



























next.jsp :



RoseIndia JSF tutorial

Rendered Output :

Html Source Code :







Enter your name below











RoseIndia JSF tutorial



Attributes that this tag uses are given below :

id : This is used to uniquely identify this component within the scope of enclosing naming container.
binding : It takes value binding expression to bind this component to the backing bean property.
rendered : It takes the boolean value (default value is "true") that is used to specify whether this component should be rendered or not.

read more “JSF subview Tag”

JSF validateDoubleRange Tag

This is one of the standard validators provided by JSF to check whether the floating point value (or that can be converted to floating point) entered in the corresponding input component is within the certain range. This range is specified by minimum and maximum attributes of this tag.The page author requires no code to write for validation. Simply use this tag in the nearest enclosing input component. If there is any fault in filling the input component then the error message flashes to show this error.

Code Description :

<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
















Rendered Output :
This is the first screen that will be rendered to the user.

When the user enters the value out of the range from 2.0 to 10.0 then validation error is displayed specifying that the user has not entered the correct value or type. Figure below shows this fact :

Html Source Code :




Enter any floating point value






This tag contains two attributes :

maximum : This attribute is used to set the maximum value allowed for this component to input
minimum :
This is used to set the minimum value allowed to be entered in the component.

read more “JSF validateDoubleRange Tag”

JSF validateLength Tag

If you want the user to input the number of characters between the certain range, suppose you want the user to fill password of more than 6 characters then this tag can be used to validate. This is one of the standard validators provided by JSF to check whether the length of the local value entered in the corresponding input component is within the certain range. This range is specified by minimum and maximum attributes of this tag. The page author requires no code to write for validation. Simply use this tag in the nearest enclosing input component. If there is any fault in filling the input component then the error message flashes to show this error. In the following example, the user has entered less than 6 characters in the password field so error message displaying that user has entered less than 6 characters in the password field.

Code Description :

<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
























Rendered Output :
This is the first screen that will be rendered to the user.

When the user enters the value less than 6 characters or more than 15 characters then validation error is displayed specifying that the user has not entered the correct value. Figure below shows this fact :

Html Source Code :




ID






PASSWORD(minimum 6 characters)










This tag contains two attributes :

maximum : This attribute is used to set the maximum length allowed for this component to input
minimum :
This is used to set the minimum length allowed to be entered in the component.

read more “JSF validateLength Tag”

JSF validateLongRange Tag

This is one of the standard validators provided by JSF to check whether the local value (a numeric value or any string that can be converted to a long.) entered in the corresponding input component is within the certain range. This range is specified by minimum and maximum attributes of this tag. The page author requires no code to write for validation. Simply use this tag in the nearest enclosing input component. If there is any fault in filling the input component then the error message flashes to show this error.

Code Description :

<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>















Rendered Output :
This is the first screen that will be rendered to the user.

When the user enters the value out of the range from 15 to 30 then validation error is displayed specifying that the user has not entered the correct value. Figure below shows this fact :

Html Source Code :












This tag contains two attributes :

maximum : This attribute is used to set the maximum value allowed for this component to input
minimum :
This is used to set the minimum value allowed to be entered in the component.

read more “JSF validateLongRange Tag”