O'Reilly logo

JavaServer Faces by Hans Bergsten

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required