How to Bind to the Train Model in JSF Pages

Creating and Reusing Fragments, Page Templates, and Components 19-3 pages use the same form, then you might find it beneficial to create page fragments containing those components in the form, and reuse those page fragments in several pages. Deciding on how many page fragments to create for one or more complex pages depends on your application, the degree to which you wish to reuse portions of a page between multiple pages, and the desire to simplify complex pages. Page fragments are incomplete JSF pages. A complete JSF page that uses ADF Faces must have the document tag enclosed within an f:view tag. The contents for the entire page are enclosed within the document tag. A page fragment, on the other hand, represents a portion of a complete page, and does not contain the f:view or document tags. The contents for the page fragment are simply enclosed within a jsp:root tag. When you build a JSF page using page fragments, the page can use one or more page fragments that define different portions of the page. The same page fragment can be used more than once in a page, and in multiple pages. For example, the File Explorer application uses one main page index.jspx that includes the following page fragments: ■ popups.jspx: Contains all the popup code used in the application. ■ help.jspx: Contains the help content. ■ header.jspx: Contains the toolbars and menus for the application. ■ navigators.jspx: Contains the tree that displays the folder hierarchy of the application. ■ contentViews.jspx: Contains the content for the folder selected in the navigator pane. Example 19–1 shows the abbreviated code for the included header.jspx page fragment. Note that it does not contain an f:view or document tag. Example 19–1 header.jspx Page Fragment ?xml version=1.0 encoding=UTF-8? jsp:root xmlns:jsp=http:java.sun.comJSPPage version=2.0 xmlns:af=http:xmlns.oracle.comadffacesrich xmlns:f=http:java.sun.comjsfcore af:panelStretchLayout id=headerStretch f:facet name=center -- By default, every toolbar is placed on a new row -- af:toolbox id=headerToolbox binding={explorer.headerManager.headerToolbox} . . . af:toolbox f:facet af:panelStretchLayout jsp:root Note: The view parts of a page fragments, declarative components, and the main page all share the same request scope. This may result in a collision when you use the same fragment or declarative component multiple times on a page and the fragments or components share a backing bean. For more information about scopes, see Section 4.6, Object Scope Lifecycles. 19-4 Web User Interface Developers Guide for Oracle Application Development Framework When you consume a page fragment in a JSF page, at the part of the page that will use the page fragment contents, you insert the jsp:include tag to include the desired page fragment file, as shown in Example 19–2 , which is abbreviated code from the index.jspx page. Example 19–2 File Explorer Index JSF Page Includes Fragments ?xml version=1.0 encoding=utf-8? jsp:root xmlns:jsp=http:java.sun.comJSPPage version=2.0 xmlns:f=http:java.sun.comjsfcore xmlns:af=http:xmlns.oracle.comadffacesrich xmlns:trh=http:myfaces.apache.orgtrinidadhtml jsp:directive.page contentType=texthtml;charset=utf-8 f:view . . . af:document id=fileExplorerDocument title={explorerBundle[global.branding_name]} af:form id=mainForm -- Popup menu definition -- jsp:include page=fileExplorerpopups.jspx jsp:include page=fileExplorerhelp.jspx . . . f:facet name=header af:group -- The file explorer header with all the menus and toolbar buttons -- jsp:include page=fileExplorerheader.jspx af:group f:facet f:facet name=navigators af:group -- The auxiliary area for navigating the file explorer -- jsp:include page=fileExplorernavigators.jspx af:group f:facet f:facet name=contentViews af:group -- Show the contents of the selected folder in the folders navigator -- jsp:include page=fileExplorercontentViews.jspx af:group f:facet . . . af:form af:document f:view jsp:root When you modify a page fragment, the pages that consume the page fragment are automatically updated with the modifications. With pages built from page fragments, when you make layout changes, it is highly probable that modifying the page fragments alone is not sufficient; you may also have to modify every page that consumes the page fragments.