background image

The form Tag

<< The uri Attribute Value | Using the Core Tags >>
<< The uri Attribute Value | Using the Core Tags >>

The form Tag

The form tag is nested inside of the view tag. As its name suggests, the form tag represents a
form, which is submitted when a button or hyperlink on the page is clicked. For the data of
other components on the page to be submitted with the form, the tags representing the
components must be nested inside the form tag. See
"Adding a Form Component" on page 329
for more details on using the form tag.
If you want to include a page containing JavaServer Faces tags within another JSP page that
includes JavaServer Faces tags, you must enclose the entire nested page in a subview tag. You
can add the subview tag on the parent page and nest a jsp:include inside it to include the page:
<f:subview id=
"myNestedPage">
<jsp:include page=
"theNestedPage.jsp" />
</f:subview>
You can also include the subview tag inside the nested page, but it must enclose all the
JavaServer Faces tags on the nested page.
The subview tag has two optional attributes: binding and rendered. The binding attribute
binds to a component that implements NamingContainer. One potential use case of binding a
subview component to a bean is if you want to dynamically add components to the subview in
the backing bean.
The rendered attribute can be set to true or false, indicating whether or not the components
nested in the subview tag should be rendered.
In summary, a typical JSP page that uses JavaServer Faces tags will look somewhat like this:
<%@ taglib uri=
"http://java.sun.com/jsf/html" prefix="h" %>
<%@ taglib uri=
"http://java.sun.com/jsf/core" prefix="f" %>
<f:view>
<h:form>
other JavaServer Faces tags and core tags,
including one or more button or hyperlink components for
submitting the form
</h:form>
</f:view>
The sections
"Using the Core Tags" on page 325
and
"Adding UI Components to a Page Using
the HTML Component Tags" on page 327
describe how to use the core tags from the JavaServer
Faces core tag library and the component tags from the JavaServer Faces standard HTML
render kit tag library.
Setting Up a Page
The Java EE 5 Tutorial · September 2007
324