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> <formid="form"
> <table> <tr> <td>Email Address:</td> <td><inputid="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> <inputid="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 ...
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.