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

Developing the HTML Template and the View Specification

This custom ViewHandler works with views described by a combination of an HTML template and a view specification file. The HTML template for the newsletter subscription view looks like this:

<html>
  <head>
    <title>Newsletter Subscription</title>
  </head>
  <body>
    <form id="form">
      <table>
        <tr>
          <td>Email Address:</td>
          <td><input id="form:emailAddr" size="50" /></td>
        </tr>
        <tr>
          <td>Newsletters:</td>
          <td>
            <span id="form:subs">
              <input type="checkbox" value="1">foo</input>
              <input type="checkbox" value="2">bar</input>
            </span>
          </td>
        </tr>
      </table>
      <input id="form:save" type="submit" value="Save" />
    </form>
  </body>
</html>

It’s a plain XHTML file with id attributes for the elements that represent JSF components. To keep the example simple, I’ve used id attribute values with the JSF naming container syntax, but a more sophisticated implementation would make it possible to use plain values instead. The reason for using XHTML instead of HTML is also to keep the implementation simple. There are parsers that can parse HTML and present it to an application as XML, so a real implementation can support both HTML and XHTML without too many modifications.

For the checkboxes, I’m using a <span> element to give the whole group one id attribute, because the whole group is handled by one JSF component. The <input> elements within the <span> element are ignored when the view is rendered, but serves a purpose during the template design to see how the page ...

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