JSF-Navigation (Navigation)

Source: Internet
Author: User

When using the JSF framework, Faces-config.xml is definitely used. And there will be a lot of navigation items.

Actually these navigation are some page jumps the thing.

The following content is from http://blog.sina.com.cn/s/blog_600046120100to0e.html

Navigation (Navigation)
Now there's a summary of the navigation in JSF, which is divided into three parts, reference and core JSF
1, static navigation
2, dynamic navigation
3, Advanced navigation
The main discussion is how to configure navigation in your Web application, that is, how to get your program to jump from one page to the next, of course, depending on your business

The actions and outcomes of logic.

1, static navigation (Navigation)
In a simple Web application, page navigation is typically statically specified, and in JSF you only need to give each button an Action property,

After the faces-config.xml in the configuration of the following can be easily implemented between the page jump problem.
For example:
But not yet, the action must match the outcome of the navigation rule in the Faces-config.xml file:
<navigation-rule>

<from-view-id>/index.jsp</from-view-id>

<navigation-case>

<from-outcome>login</from-outcome>

<to-view-id>/welcome.jsp</to-view-id>

</navigation-case>

</navigation-rule>
This indicates that if the button is clicked in/index.jsp, the page will jump to/welcome.jsp.
Note: The View-id here must start with a "/" extension of. jsp. Example: If you set From-view-id to/index.faces, you will not

able to work.

Let's look at the following navigation rules:
<navigation-rule>

<navigation-case>

<from-outcome>logout</from-outcome>

<to-view-id>/logout.jsp</to-view-id>

</navigation-case>

</navigation-rule>

You can see that he has no from-view-id, which means: No matter what you click on any page in the entire Web program, as long as outcome is logout

, she will jump to the/logout.jsp page.

Let's look at the following navigation rules:

<navigation-rule>

<from-view-id>/index.jsp</from-view-id>

<navigation-case>

<from-outcome>login</from-outcome>

<to-view-id>/welcome.jsp</to-view-id>

</navigation-case>

<navigation-case>

<from-outcome>signup</from-outcome>

<to-view-id>/newuser.jsp</to-view-id>

</navigation-case>

</navigation-rule>


We can see that she has an identical from-view-id meaning that in/index.jsp if you trigger the outcome to login, the page

Will jump to/welecom.jsp, if for signup's words jump to/newuser.jsp page. In fact, we're going to use this rule often.

Configuration.

Note: If there is no navigation rule to match a given action, the current page will simply be re-displayed.


2, dynamic navigation (Navigation)
In most web programs, navigation is not static. The process of the page depends not only on the button you clicked on, but also on the type of

Content to judge. The most common is to submit a processing landing page, there may be two kinds of results: Success orfailure! results (outcome)

will depend on certain calculations, such as whether the user name and password are legal.

To enable dynamic navigation, the submit button must have a method to refer to, for example:

Logincontroller is a managed bean of a class that must have a method named Verifyuser, which returns a string for

The Action property is used, as this method might be:
String Verifyuser () {
if (...)
Return "Success";
Else
return "Failure";
}
Note: If an action method returns null, the page itself is displayed again.


3, Advanced navigation

As can see from the syntax diagram, each navigation-rule andnavigation-case element can

There are arbitrary description, display-name, and icon elements. These elements is intended for use

In Builder tools, and we does not discuss them further.

Let's look at the following navigation rules:
<navigation-case>

<from-outcome>success</from-outcome>

<to-view-id>/success.jsp</to-view-id>

<redirect/>

</navigation-case>

You'll find a redirect element in the back of the To-view-id, redirecting the page is Slowerthan forwarding

Because another round the browser is involved. However,the redirection gives the

Browser a chance to update its address field.
Note: There is no redirect, the original URL (localhost:8080/javaquiz/index.faces) in you from/index.jsp to/success.jsp

After the address bar has not changed, the contrary changed, became localhost:8080/javaquiz/success.faces.

Let's look at the following navigation rules:
<navigation-rule>

<from-view-id>/secure/*</from-view-id>

<navigation-case>

. . .

</navigation-case>

</navigation-rule>
You will find that the wildcard character (wildcards) is used in From-view-id, and all pages under the/secure directory apply the navigation rules. Similarly:
<from-view-id>/*</from-view-id>or<from-view-id>*</from-view-id> will apply all of the pages.

Let's look at the following navigation rules:

<navigation-rule>
    <from-view-id>/index/zhuce/denglu.jsp</ From-view-id>
    <navigation-case>
       <from-action>#{loginbean.dologin}</from-action>
      < From-outcome>success</from-outcome>
      <to-view-id>/index/ Zhuce/welcome.jsp</to-view-id>
    </navigation-case>
     <navigation-case>
<from-action>#{loginbean.dologin}</from-action>
         <from-outcome>failed</from-outcome>
         <to-view-id>/index/zhuce/denglu.jsp</to-view-id>
    </navigation-case>
</navigation-rule>
You'll find one more <from-action>, and it doesn't seem right on top, Because the from-action typically displays the

in the following case

The flexibility:

That flexibility can is useful if you have both separate Actionswith the same action string, or

Both action method references that return the same actionstring.
If you have a single action but have the same actions string or two identical actionmethod return the same action

String.
For example: both Answeraction and startoveraction return to again
<navigation-case>

<from-action>#{quiz.answerAction}</from-action>

<from-outcome>again</from-outcome>

<to-view-id>/again.jsp</to-view-id>

</navigation-case>

<navigation-case>

<from-action>#{quiz.startOverAction}</from-action>

<from-outcome>again</from-outcome>

<to-view-id>/index.jsp</to-view-id>

</navigation-case>

For example, suppose that in our quiz program, Startoveraction returns the string "again" instead of "Startover". Answeraction may also return the same string. To differentiate between the two navigation conditions, you can use the from-action element. The content of the element must be the same as the method expression string for the Action property.

<navigation-case>
<from-action>#{quiz.answerAction}</from-action>
<from-outcome>again</from-outcome>
<to-view-id>/again.jsp</to-view-id>
</navigation-case>
<navigation-case>
<from-action>#{quiz.startOverAction}</from-action>
<from-outcome>again</from-outcome>
<to-view-id>/index.jsp</to-view-id>
</navigation-case>

Description

The navigation handler does not call #{...} The method in the delimiter. The method has been called before the navigation handler is processed. The navigation handler simply uses the From-action string as a primary key for finding matching navigation

JSF-Navigation (Navigation)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.