JSF: The "H" Library: For Live JSF Training, Please See JSP/servlet/Struts/JSF Training Courses at
JSF: The "H" Library: For Live JSF Training, Please See JSP/servlet/Struts/JSF Training Courses at
Documentation on h: Library
• Javadoc extensions can now generate
online API for JSP tag libraries
http://java.sun.com/j2ee/javaserverfaces/1.1_01/docs/
tlddocs/index.html
Form Basics
http://courses.coreservlets.com/ -- Hands-on, customized training for Java, servlets, JSP, Struts, and JSF.
h:form
• Corresponding HTML element
– <FORM …>
• Notable feature
– You do not specify an action
• Attributes
– enctype. Encoding type.
• application/x-www-form-urlencoded (default)
• multipart/form-data
– target. Frame cell in which to display results.
– onsubmit. JavaScript code to run before form submission
• Can perform client-side field validation
• Examples
– See all previous sections
9 J2EE training and tutorials: http://www.coreservlets.com
h:inputText
• Corresponding HTML element
– <INPUT TYPE="TEXT" …>
• Attributes
– value. Corresponding bean value.
• value="#{beanName.propertyName}"
• Used for both initial value and submitted value
– valueChangeListener. Method to fire when form submitted and
value has changed from previous value.
• Use onchange="submit()" and immediate with this
– onchange. JavaScript to run when value changes
– immediate. Use to indicate listener bypasses validation
– required. Flag indicating if user must supply a value.
• If omitted, form redisplayed and error message stored.
– validator. Method to perform validation.
• See validation section
• Examples
10
– See all previous sections J2EE training and tutorials: http://www.coreservlets.com
h:inputSecret
• Corresponding HTML element
– <INPUT TYPE="PASSWORD" …>
• Attributes
– value. Corresponding bean value.
• value="#{beanName.propertyName}"
• Used for submitted value only
– valueChangeListener. Method to fire when form
submitted and value has changed from previous value.
• Again, use onchange="submit" and immediate with this
– required. Flag indicating if user must supply a value.
• If omitted, form will be redisplayed and error message
stored.
– converter, validator. Methods to perform string
conversion and data validation.
• See validation section
• Example
11 – See all previous sections J2EE training and tutorials: http://www.coreservlets.com
© 2005 Marty Hall
h:commandLink
• Corresponding HTML element
– <A HREF="..."> with attached JavaScript that submits
form when link is pressed
– JavaScript inserted automatically by JSF
• Attributes
– value. Text of the link. A static string is common, but
you can also change value dynamically
– action. Action controller method to fire when form
submitted. Runs after all listeners have completed.
– actionListener. Listener method to fire when form
submitted. Runs before action controller.
http://courses.coreservlets.com/ -- Hands-on, customized training for Java, servlets, JSP, Struts, and JSF.
Elements That
Display Lists of Items
http://courses.coreservlets.com/ -- Hands-on, customized training for Java, servlets, JSP, Struts, and JSF.
Outputting Values
http://courses.coreservlets.com/ -- Hands-on, customized training for Java, servlets, JSP, Struts, and JSF.
Output Options
• h:outputText
– Outputs bean property or collection element
• Values from properties file loaded into a collection via
f:loadBundle
– Roughly equivalent to bean:write from Struts
– Attributes
• styleClass or style: results in SPAN element instead
• escape: false value means not to filter < and >
• h:outputFormat
– Outputs parameterized error messages
– Parameters supplied with f:param
– See section on resource bundles
Custom Components
http://courses.coreservlets.com/ -- Hands-on, customized training for Java, servlets, JSP, Struts, and JSF.
Custom Components
• You can roll your own complex components
• This is an advanced topic
– See Chapter 9 of Core JSF for details
• JSF comes bundled with demo components
that are ready to be used or adapted
– Deploy jsf_install_dir/samples/jsf-components.war and
access http://localhost/jsf-components/
– Included components
• Chart
• Graph or Tree
• Tabbed Pane
• Scroller
• Repeater
• Image Map
24 J2EE training and tutorials: http://www.coreservlets.com
Custom Components
• Chart • Graph or Tree
• Scroller
Custom Components
• Repeater
• Image Map
Questions?