Creating a JSF Data Table for Entity Data

See Also

You can use the Data Table from Entity dialog to generate a JSF data table that contains columns for all properties contained in an entity class. In order to make use of this facility, you must already have a JSF managed bean created to handle any back-end data associated with the entity class.

If you use this dialog without having an associated managed bean, you can enter a name for the managed bean in the dialog, and that name will be used in the page regardless of whether it is valid or not. You can then create a managed bean using the IDE's Managed Bean wizard, or if you use the JSF Pages from Entity Classes wizard, managed beans are generated for all selected entity classes.

To generate a JSF data table from an entity class:

  1. Open any Facelets page in the editor.
  2. Make sure that you have declared the JSF tag libaries in the page's root element (typically the <html> tag), as shown below:
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:f="http://java.sun.com/jsf/core"
  3. Either type 'jsf' in the editor, press Ctrl-Space, then select the JSF Data Table from Entity option, or, in the Palette, click and drag the JSF Data Table from Entity component into the desired location in the editor and release the mouse button. The JSF Table from Entity dialog box opens.
  4. In the Entity Bean drop-down, select the entity class that you want to generate the data table from. The IDE scans the project for all entity classes and makes them accessible from the drop-down list.
  5. In the Managed Bean Property field, select a property. The property you choose must return a List of objects that correspond to the entity bean you selected in the Entity Bean drop-down.
  6. Click OK. The IDE generates code for your Facelets page. For example, a managed bean that contains a property that returns a List of Product objects would display similarly to the following:
    <f:view>
        <h:form>
            <h1><h:outputText value="List"/></h1>
            <h:dataTable value="#{productController.productItems}" var="item">
                <h:column>
                    <f:facet name="header">
                        <h:outputText value="ProductId"/>
                    </f:facet>
                    <h:outputText value="#{item.productId}"/>
                </h:column>
                ...
                [ Other columns added here. ]
                ...
            </h:dataTable>
        </h:form>
    </f:view>
  7. Optionally, remove any of the entries for columns that you do not want to display in your Facelets page.

You can customize the template that specifies the generated code for the JSF Form from Entity dialog. To do so, click the Customize Template link in the dialog, and in the template file make any changes to better suit your work patterns. Save the file. The next time you use the dialog, the changes you made to the template will appear in the generated code.

See Also
Creating a JSF Form for Entity Data
Working with JSF Components in the Palette
Editing JSF Pages
About JavaServer Faces Framework Support

Legal Notices