HTML and CSS Reference
In-Depth Information
Listing 4-31.
JSF Input Form for Entering Car Information (intro.xhtml)
<h:form>
<h:panelGrid columns="3">
<h:outputText value="Model:"></h:outputText>
<h:inputText id="model"
value="#{car.model}"
required="true"
requiredMessage="You need to specify car model">
</h:inputText>
<h:message for="model" styleClass="errorMessage"/>
<h:outputText value="Color:"></h:outputText>
<h:inputText id="color"
value="#{car.color}"
required="true"
requiredMessage="You need to specify car color">
</h:inputText>
<h:message for="color" styleClass="errorMessage"/>
<h:outputText value="Car Number:"></h:outputText>
<h:inputText id="number"
value="#{car.number}"
required="true"
requiredMessage="You need to specify car number">
<f:validateLongRange minimum="1" maximum="9999999999"/>
</h:inputText>
<h:message for="number" styleClass="errorMessage"/>
</h:panelGrid>
<h:commandButton value="View car details"
action="car?faces-redirect=true&includeViewParams=true" />
</h:form>
As shown in the bolded lines, in order to allow the JSF command button to navigate to our RESTful page (car.
xhtml) in a RESTful way (target page name and parameters will appear in the browser address bar), we need to add
the following two parameters to
action
outcome of
UICommand
:
1.
faces-redirect
: setting
faces-redirect
parameter to
true
allows the current page to be
redirected (not forwarded) to the target page (as we know from Chapter 2).
2.
includeViewParams
: setting
includeViewParams
to
true
inside the
action
outcome allows
ActionSource2
component to include view parameters when performing navigation. Keep
in mind that the included view parameters must be declared in the target JSF page, which
is (
car.xhtml
) in our example.
Assuming that valid data are entered in the
intro.xhtml
page and then the
"View car details"
button is
clicked, the page will be redirected to (
car.xhtml
) page with the following parameters in the browser address bar:
contextPath/car.xhtml?model=xxx&color=yyy&number=zzz