JSF Binding

In this article we’ll discuss about the JSF Binding. The different types of event handling ,validation and widget library are explained.

JSF – Event Handling

JSF makes it easy to designate Java code that is invoked when forms are submitted. The code can respond to particular buttons, changes in particular values, certain user selections, and so on.

Method Bindings

<h:outputText value=“#{bundle.welcome}” rendered=“#{bean.showWelcome}”/>

Value Change Listeners

<h:selectOneMenu value=“#{bean.type}” onchange=“submit()” 
immediate=“true” valueChangeListener=“#{bean.change}”>
<f:selectItems value=“#{bean.types}”>
</h:selectOneMenu>

Command Actions

<h:commandButton action=“#{bean.submit}”/>

Action Listeners

<h:commandButton actionListener=“#{bean.listen}” action=“#{bean.submit}”/>

JSF – Input Validation

Standard Validators

<h:inputText id=“card” value=“#{bean.card}” required=“true”>
<f:validateLength minimum=“13”/>
</h:inputText>
f:validateDoubleRange
f:validateLongRange
f:validateLength
Custom Validators
Validation Errors
<h:message for=“card”/>
<h:messages/>

 

JSF – Define Configuration Files

Faces-Config-bean.xml (For defining all Managed Beans)

<faces-config>
<managed-bean>
<managed-bean-name>AllCompanyPageBean</managed-bean-name>
<managed-bean-class>com.citi.company.beans.AllCompaniesPageBean</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
</managed-bean>
</faces-config>

Faces-Config-Nav.xml (For Navigational Rule)

<faces-config>
<navigation-rule>
<navigation-case>
<from-outcome>ic$CompanyInterationFlow_displayAllCompanies</from-outcome>
<to-view-id>/xAdvisorWeb/bundles/Company/jsf/AllCompaniesScreen.jsp</to-view-id>
</navigation-case>
</navigation-rule>

JSF – FacesConfig.xml Snapshot

<lifecycle>
<phase-listener>com.ibm.faces.webapp.ValueResourcePhaseListener</phase-listener>
phase-listener>xyz.web.PhaseListener.RestoreViewPhaseListener</phase-listener>
</lifecycle>
<!-- variable/property resolver registration -->
<application>
<variable-resolver>com.ibm.faces.databind.SelectItemsVarResolver</variable-resolver>
<property-resolver>com.ibm.faces.databind.SelectItemsPropResolver</property-resolver>
<locale-config>
<default-locale>en</default-locale>
</locale-config>
<message-bundle>xyz.web.properties.webMessages_en</message-bundle>
</application>
<validator>
<validator-id>ValidateEmail</validator-id>
<validator-class>xyz.web.validation.ValidateEmail</validator-class>
</validator>
<validator>

 

JSF – JWL (JSF Widget Library )

JWL (The JSF Widget Library) consists of a large number of complex components. These enable you to speedily build rich and reliable Web applications. The Tree Control is a prime example of such a component. The JWL components are currently shipping with IBM Web sphere Studio Application Developer 5.1.2 (WSAD), IBM Rational Application Developer 6.0 (IRAD) and beyond. The tooling provided by IRAD allows you to simply and quickly develop complex Web applications using these components.

Required Jar files are odc-jsf.jar, jsf-impl.jar
JSF – JWL Tree Component

  • Tree component provides a hierarchical structure to store data on the browser.
  • It supports client-side data storage. This means faster access to data, quicker page refreshes and less roundtrips to the server.
  • User-friendly and extremely powerful Web component
  • The JWL component also has a number of custom event handlers at both a tree and node level.