Processing Row-Specific Events

A very common application feature is to have one table with summary information (a master table) with each row linked to the details about the item in that row. The sample application uses this approach for selecting an individual report to work with. To implement this feature, you must figure out which master table row the user selected and make the corresponding details available for edit or display.

In the final version of the sample application, both the master table and the details are displayed on the same screen, but let’s look at how to implement it using two screens first, so we can focus on one thing at the time. Figure 10-1 shows the first rough cut of the reports list screen, with the report titles as links to a report details screen.

Simple reports list screen
Figure 10-1. Simple reports list screen

Example 10-1 shows the JSP page for this initial version.

Example 10-1. Reports list with links (expense/stage1/reportListArea.jsp)
<%@ page contentType="text/html" %>
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>

<f:view>
  <h:form>
    <h:dataTable value="#{reportHandler.reportsModel}" var="report">
      <h:column>
        <f:facet name="header">
          <h:outputText value="Title" />
        </f:facet>
        <h:commandLink action="#{reportHandler.select}" immediate="true">
          <h:outputText value="#{report.title}" />
        </h:commandLink> </h:column> ...

Get JavaServer Faces now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.