Java Server Faces JSF Tags Topics in This

  • Slides: 15
Download presentation
Java Server Faces JSF Tags

Java Server Faces JSF Tags

Topics in This Section Introduction to JSF Tags Types of JSF Tags JSF Html

Topics in This Section Introduction to JSF Tags Types of JSF Tags JSF Html Tags Library JSF Core Tags Library JSF 2 JSF Tags

Introduction to JSF Tags JSF application typically uses JSP pages to represent views. JSF

Introduction to JSF Tags JSF application typically uses JSP pages to represent views. JSF provides useful special tags to enhance these views. Each tag gives rise to an associated component. JSF provides 43 tags in two standard JSF tag libraries: 1. 2. JSF Core Tags Library and JSF Html Tags Library Even a very simple page uses tags from both libraries. <%@ taglib uri=”http: //java. sun. com/jsf/core “ prefix=”f” %> <%@ taglib uri=”http: //java. sun. com/jsf/html “ prefix=”h” %> <f: view> <h: form> …………… </h: form> </f: view> 3 JSF Tags

Types of JSF Tags In the above code fragment we have imported two JSF

Types of JSF Tags In the above code fragment we have imported two JSF tag libraries with the help of taglib directive. JSF Core Tag Library contains set of JSF core tags while JSF Html Tags Library contains set of html tags. Prefix is used to use tags defined in tag library. Here we are using conventional names f and h for Core & Html tags respectively. We have the choice to choose any name for the prefixes Two XML-based tag libraries (core and html) for expressing a Java. Server Faces interface within a view template (can be used with both JSP or Facelets) 4 JSF Tags

JSF Html Tags: These tags represent html components like text fields, buttons, form. Html

JSF Html Tags: These tags represent html components like text fields, buttons, form. Html tags can be divided into following categories: Ø Inputs (input. Text, input. Textarea) Ø Outputs (output. Text, output. Label) Ø Commands (command. Button) Ø Selections (select. One. Radio, select. One. Listbox, select. One. Menu for radio buttons, list boxes, menu etc) Ø Layouts (panel. Grid) Ø Data table (data. Table) Ø Errors and messages (message, messages) 5 JSF Tags

JSF Html Tags: Some examples have been given below to understand how to use

JSF Html Tags: Some examples have been given below to understand how to use these tags and its attributes: <h: input. Text id=“ID 1” value=“value” /> creates a single line text input control where id attribute is used to uniquely identify the component rendered by this tag and value attribute sets the current value of the component. <h: output. Text id="ID 2" value="Welcome"/> creates a single line text output where id attribute uniquely identifies the rendered component and current value is set by value attribute. 6 JSF Tags

JSF Html Tags: <h: command. Button id="submit“ value="go“ action="next. Page"> </h: command. Button> creates

JSF Html Tags: <h: command. Button id="submit“ value="go“ action="next. Page"> </h: command. Button> creates a command button where value attribute sets the value that is displayed on the button when it is rendered and action attribute is used to invoke a method defined in backing bean when a user does an action on the component. According to the return of the invoked method it is determined which view is to be displayed next. 7 JSF Tags

JSF Html Tags: Example <h: input. Text value="#{form. test. String}" readonly="true"/> <h: input. Secret

JSF Html Tags: Example <h: input. Text value="#{form. test. String}" readonly="true"/> <h: input. Secret value="#{form. passwd}" redisplay="false"/> <h: input. Text value="input. Text" style="color: Yellow; background: Teal; "/> <h: input. Text value="1234567" size="5"/> <h: input. Text value="1234567890" maxlength="6" size="10"/> 8 JSF Tags Result

All JSF Html Tags: In JSF Html Tag Library there are 25 core tags.

All JSF Html Tags: In JSF Html Tag Library there are 25 core tags. All JSF Html Tags : • column creates column in a data. Table • command. Button creates button • command. Link creates link that acts like a pushbutton • data. Table creates a table control • form creates a form • graphic. Image displays an image • input. Hidden creates hidden field • input. Secret creates input control for password • input. Text creates text input control (single line) • input. Textarea creates text input control (multiline) • message displays the most recent message for a component • messages displays all messages • output. Format creates output. Text, but formats compound messages • output. Label creates label • output. Link creates anchor 9 JSF Tags

All JSF Html Tags: • output. Text creates single line text output • panel.

All JSF Html Tags: • output. Text creates single line text output • panel. Grid creates html table with specified number of columns • panel. Group used to group other components where the specification requires one child element • select. Boolean. Checkbox creates checkbox • select. Many. Checkbox creates set of checkboxes • select. Many. Listbox creates multiselect listbox • select. Many. Menu creates multiselect menu • select. One. Listbox creates single select listbox • select. One. Menu creates single select menu • select. One. Radio creates set of radio buttons 10 JSF Tags

JSF Core Tags: These tags allows you to take advantages of features of JSF

JSF Core Tags: These tags allows you to take advantages of features of JSF framework, like validation, conversion , event handling. Core library is stepchild of Html library. i. e. core library supports the html library. Core tag library also contains tags for views and sub-views , loading resource bundle, adding arbitrary text to a page. Some examples of JSF core tags are: f: view tag is used to create top level view f: subview tag is used to create subview of a view. f: validator tag is used to add a validator to a component. f: converter tag is used to add an arbitrary converter to a component. f: action. Listener tag is used to add an action listener to a component. f: value. Change. Listener tag is used to add a valuechange listener to a 11 component JSF Tags

JSF Core Tags: Some examples have been given below to understand how to use

JSF Core Tags: Some examples have been given below to understand how to use these tags: <f: view locale="en"> <h: output. Text value="label" /> </f: view> f: view tag is used to create top level view and is a container for all JSF component tags on a page. Where locale attribute provides several options for presenting localized views of your application. Here "en" represents English and if we give value "fr" to locale attribute then french view will be displayed. So this attribute is useful for internationalization purpose. <f: view> <h 1>head</h 1> <p>view</p> <f: subview id="sub_id"> <c: import url="second. jsp" /> </f: subview> </f: view> 12 JSF Tags

JSF Core Tags: Here f: subview tag is like container for the JSF components

JSF Core Tags: Here f: subview tag is like container for the JSF components contained in an included JSP page (second. jsp). <h: input. Text id="txt_id" value="txt_value"> <f: validator. Id="Txt_Validator" /> </h: input. Text> The Validator tag registers a Validator on the component associated with the enclosing tag. In validator. Id field, we give the value of one of the validator-id element of a validator in your Faces configuration file. 13 JSF Tags

All JSF Core Tags: In JSF Core Tag Library there are 18 core tags

All JSF Core Tags: In JSF Core Tag Library there are 18 core tags : All JSF Core Tags: f : view Creates the top-level view f: subview Creates a subview of a view f: attribute Adds an attribute to a component f: param Constructs a parameter component f: converter Adds an arbitrary converter to a component f: converter. Date. Time Adds a datetime converter to a component f: converter. Number Adds a number converter to a component f: action. Listener Adds an action listener to a component f: value. Change. Listener Adds a valuechange listener to a component f: validator Adds a validator to a component f: validate. Double. Range Validates a double range for a component’s value f: validate. Length Validates the length of a component’s value f: validate. Long. Range Validates a long range for a component’s value f: facet Adds a facet to a component f: load. Bundle Loads a resource bundle, stores properties as a Map f: selectitems Specifies items for a select one or select many component f: selectitem Specifies an item for a select one or select many component JSF Tags 14 f: verbatim Adds markup to a JSF page

THANK YOU… 15 JSF Tags

THANK YOU… 15 JSF Tags