Conditionally Include Components Using Bean Properties
All JSF action elements also
have a rendered
property. If you set it to false, the component
(and all its children) remains in the view but it’s
never asked to render itself. In Example 6-6, the
rendered attributes for the Accept and Reject
buttons are set to value binding expressions that delegate the
rendering decision to the reportHandler bean.
Here’s how the ReportHandler
class implements the corresponding getter methods:
public boolean isAcceptRendered( ) {
return isManager( );
}
public boolean isRejectRendered( ) {
return isManager( );
}The JSF <h:commandButton> action elements in
Example 6-6 use value binding expressions that get
the appropriate values from the reportHandler bean
for the disabled and rendered
attribute values, pushing all the detailed decisions to the bean.
Placing this type of logic in a bean instead of in the page has clear
maintenance advantages, so I recommend that you follow this pattern
for your own applications.
In this chapter, we looked at how JSF components are created and how they generate the HTML elements for the browser in some detail. In the next chapter, we’ll look at what happens when the user fills out a form and submits it to JSF for processing.
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access