Check also:
The three golden rules of use
JSF Navigation Tutorial - Implicit Navigation
JSF Navigation Tutorial - Declarative Navigation
JSF Navigation Tutorial - Conditional Navigation
JSF Navigation Tutorial - Programmatic Navigation
JSF VS Series: Implicit Navigation VS Declarative (explicit) Navigation
Preemptive navigation is available starting with JSF 2.0. The navigation rules are more permissive and they are evaluated during the Render Response phase instead of the Invoke Application phase.
The three golden rules of use
JSF Navigation Tutorial - Implicit Navigation
JSF Navigation Tutorial - Declarative Navigation
JSF Navigation Tutorial - Conditional Navigation
JSF Navigation Tutorial - Programmatic Navigation
JSF VS Series: Implicit Navigation VS Declarative (explicit) Navigation
Preemptive navigation is available starting with JSF 2.0. The navigation rules are more permissive and they are evaluated during the Render Response phase instead of the Invoke Application phase.
This is known as predetermined navigation or preemptive navigation. The
current view ID and specified outcome are used to determine the target view ID.
Afterwards, the target view ID is translated into a bookmarkable URL and used as the hyperlink's target. Practically, the URL
is prepared without user interaction.
The main usage of preemptive navigation appears in bookmarkable
component tags, <h:link/>
and <h:button/>.
For example, the following are two classical examples of preemptive navigation:
<h:link
value="Success" outcome="success"/>
<h:button
value="Success" outcome="success"/>
When the application starts, you can check the source code of the page
to see how the corresponding URLs were mapped in the HTML tag <a/> in case of <h:link/>, and
the HTML tag <input
type="button"/> in case of <h:button>. Even if you never use those
URLs, they are ready to serve. Well,
before JSF 2.0, navigation rules were explicitly the domain of POST requests (NavigationHandler.handleNavigation()
was doing the dirty job behind the scene), but the new support for GET-based
navigation and bookmarkability takes navigation to another level of flexibility
and transparency (for example, the ConfigurableNavigationHandler API).
The interesting part here is how the query string of a URL is assembled.
The simplest case consists of the implicit query string parameter as shown in
the following code:
<h:link
value="Done" outcome="done?id=done"/>.
But, you can also use <f:param/>
and/or <f:viewParam/>.
Another way consists in using the <view-param/> tag nested in a <redirect/> tag
in a navigation case. For example, we can add query string parameters to a
redirect URL in the navigation rules. Let's create the following button:
<h:commandButton
value="Success" action="#{playerBean.playerDone()}"/>
Also, a silly method named playerDone is as follows:
private String
player;
public String
getPlayer() {
return player;
}
public void
setPlayer(String player) {
this.player = player;
}
public String
playerDone() {
player = "Rafael Nadal";
return "done";
}
Now, we can add the player
property value (of course, you can add any other value) as a parameter in the
query string of the redirection navigation URL:
<navigation-rule>
<from-view-id>/index.xhtml</from-view-id>
<navigation-case>
<from-action>#{playerBean.playerDone()}</from-action>
<from-outcome>done</from-outcome>
<to-view-id>/success.xhtml</to-view-id>
<redirect>
<view-param>
<name>playerparam</name>
<value>#{playerBean.player}</value>
</view-param>
</redirect>
</navigation-case>
</navigation-rule>
A URL like this will be of the format (notice how the request parameter
was attached based on the navigation rule) http://host:port/app-name/faces/success.xhtml?playerparam=Rafael+Nadal.
The playerparam
value will be available through the param implicit object:
#{param['playerparam']}
The complete application is available here.
Niciun comentariu :
Trimiteți un comentariu