HTML and CSS Reference
In-Depth Information
as known from Chapter 1, JSF conversion is about converting the http request parameters to the correspond-
ing Java types in order to eliminate the overhead required from the developer to implement this functionality for every
web application. In this example, the <f:convertNumber/> converter registers a number converter to its parent input
text component ( sleepingHours ), and by setting the integerOnly attribute to true , only the integer part of the input text
value will be formatted and parsed. Setting the maxIntegerDigits to 2 means that the maximum number of the digits of
the integer to be parsed and formatted will be 2 (the conversion and validation will be covered in detail in Chapter 3).
Note
When the "Check my sleeping hours" commandButton is clicked, it produces the "proceed" outcome, and
based on the user input, we want to display the proper result page. Thanks to the JSF conditional navigation, this can
be done from the Faces configuration file, as shown in Listing 2-35.
Listing 2-35. The Conditional Navigation in the faces-config.xml File
<faces-config ...>
<navigation-rule>
<from-view-id>/input.xhtml</from-view-id>
<navigation-case>
<if>#{sleeping.hours le 9 and sleeping.hours ge 7}</if>
<from-outcome>proceed</from-outcome>
<to-view-id>/normal.xhtml</to-view-id>
</navigation-case>
<navigation-case>
<if>#{sleeping.hours lt 7}</if>
<from-outcome>proceed</from-outcome>
<to-view-id>/below.xhtml</to-view-id>
</navigation-case>
<navigation-case>
<if>#{sleeping.hours gt 9}</if>
<from-outcome>proceed</from-outcome>
<to-view-id>/above.xhtml</to-view-id>
</navigation-case>
</navigation-rule>
</faces-config>
The <if> element is a new one that has been introduced since JSF 2.0 (the conditional navigation feature was
originally taken from the JBoss Seam and included as part of the JSF 2.0). In order to match a specific navigation
case containing an <if> element, it is required that the content of the <if> element be evaluated to true . As you see
in the previous listing, the <if> element content can be a complete JSF EL Expression; in the first navigation case,
the <if> element checks that the #{sleeping.hours} value is less than 9 and greater than 7. If the first navigation
case is matched, then the target navigation page will be the normal.xhtml . The second <if> element in the second
navigation case checks that the #{sleeping.hours} value is less than 7. If the second navigation case is matched then
the target navigation page will be the below.xhtml . Finally, the third <if> element in the third navigation case checks
that the #{sleeping.hours} value is greater than 9. If the third navigation case is matched, then the navigation target
page will be the above.xhtml .
 
 
Search WWH ::




Custom Search