In the original version of the trivia quiz web application there are 3 JSF pages that share content with similar form: first.xhtml, rest.xhtml, and done.xhtml. These JSF pages are all constructed using subsets of the following:
All except the last component appear on multiple JSF pages. If web application maintenance requires changes to any of the shared components then for consistency the changes need to be made to all pages that use the affected components. This increases the maintenance effort and increases the chance of forgetting to make the change to one of the affected pages.
This problem can be alleviated by consolidating the pages into a single page, making the first.xhtml, rest.xhtml, and done.xhtml JSF pages into virtual pages. The consolidated page, say quiz.xhtml, uses conditional rendering to display only those components that are needed for a virtual page. The virtual pages are determined by boolean conditions. These boolean conditions control the rendering of the components that are not needed in all of the virtual pages.
After identifying parts of pages that you want to consolidate into a single page, create a new page with all of the desired components. Then wrap content that you want displayed conditionally in a h:panelGroup tag as follows.
<h:panelGroup rendered="condition-expression"> group-content </h:panelGroup>
The group-content can be a mix of text and various tags. The condition-expression in the rendered attribute can be any value expression that evaluates to a boolean. Normally it is a value expression for a boolean-valued bean property. You may need to add bean properties to support conditional rendering.
For components that consist of a single tag with a h: prefix it is not necessary to use a h:panelGroup wrapper. All such tags can have a rendered attribute.