Adding a JSF Data Table to a JSP Page
See Also
A JSF data table is a JSF component that provides a way of iterating over each
entry in a data source and displaying the entry's information in an HTML table.
You can create an empty data table or generate data table code from an existing
entity class.
To generate an empty JSF data table:
- Open any JSP page.
- Make sure that you have declared the JSF tag libaries in the page, as shown
below:
<%@taglib prefix="f" uri="http://java.sun.com/jsf/core"%>
<%@taglib prefix="h" uri="http://java.sun.com/jsf/html"%>
- In the Palette window, expand the JSF category. Click and drag the JSF Data
Table entry into the desired location in the JSP file and release the mouse
button.
- In the dialog box, select Empty Table and click OK.
The IDE enters the following code in the JSP page:
<f:view>
<h:form>
<h:dataTable value="#{arrayOrCollectionOf}" var="item">
</h:dataTable>
</h:form>
</f:view>
- Replace the arrayOrCollectionOf variable with a property in a JSF
managed bean that holds all of the items in your data source. Then code a
data column for each of the data source's columns that you want to display
in the file.
To generate a JSF data table from an entity class:
- Open any JSP page.
- Make sure that you have declared the JSF tag libaries in the page, as shown
below:
<%@taglib prefix="f" uri="http://java.sun.com/jsf/core"%>
<%@taglib prefix="h" uri="http://java.sun.com/jsf/html"%>
- In the Palette window, expand the JSF category. Click and drag the JSF Data
Table entry into the desired location in the JSP file and release the mouse
button.
- In the dialog box, select from Table Generated for Entity Class and specify
the full entity class name, including the package name. You can click Browse
to search all classes in the project contents and classpath. When you have
entered the class name, click OK.
The IDE enters the following code in the page:
<f:view>
<h:form>
<h1><h:outputText value="List"/></h1>
<h:dataTable value="#{arrayOrCollectionOfclass-name}" var="item">
<h:column>
<f:facet name="header">
<h:outputText value="column1"/>
</f:facet>
<h:outputText value="#{item.column1}"/>
</h:column>
...
</h:dataTable>
</h:form>
</f:view>
- Replace the arrayOrCollectionOfclass-name variable with a property
in a JSF managed bean that holds all of the entries in the data source. Note
that the JSF managed bean is often not the entity class itself but a separate
controller class.
- The IDE generates a column entity for each column of data to which
the entity class provides access. Remove any of the column entities
for columns that you do not want to display in your JSP file.
- See Also
- About Web Application Frameworks
- Adding JSF Support to an Existing Application
- About CRUD Applications
- Creating an Entity Class
- Generating Persistent Entity Classes from a Database
Legal Notices