O'Reilly logo

JavaServer Faces by Hans Bergsten

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Using Value Binding Expressions

Let’s improve the filtering criteria form by binding the fields to properties of the ReportHandler class. Example 6-3 shows the new filtering criteria page with the value binding expressions added.

Example 6-3. New filtering criteria form with value binding expressions added (expense/stage2/filterArea.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:messages layout="table" />
  <h:form>
    From: <h:inputText size="8" value="#{reportHandler.from}" />
    <br>
    To: <h:inputText size="8" value="#{reportHandler.to}" />
    <br>
    Status:
    <h:selectManyCheckbox value="#{reportHandler.status}">
      <f:selectItem itemValue="1" itemLabel="Open" />
      <f:selectItem itemValue="2" itemLabel="Submitted" />
      <f:selectItem itemValue="3" itemLabel="Accepted" />
      <f:selectItem itemValue="4" itemLabel="Rejected" />
    </h:selectManyCheckbox>
    <p>
    <h:commandButton value="Filter" />
  </h:form>
</f:view>

The value attributes for the input components contain value binding expressions that point to the corresponding properties in a ReportHandler instance available through a variable named reportHandler. If you run this page, you’ll see that the default dates returned by the getFrom() and getTo( ) methods shown in Example 6-2 end up in the input fields, and the same goes for the default choices returned by the getStatus() method.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required