Reprint, please indicate the original author, the translator, and the source.
JSF Navigation by Examples JSF navigation file setting examples of: Sergey Smirnov translation: fei See the original http://forum.exadel.com/viewtopic.php?t=579 The JavaServer Faces (JSF) framework provides some of Navigation navigation rules, You can define the page navigation between View (most of which is a JSP page) when designing a website application. These rules are defined in the JSF configuration file together with other settings. The name of this file is generally Faces-Config.xml. However, you can change this file name to other names, and you can even use multiple profiles to store related JSF configuration information, as long as you do the following settings in the web.xml file:
Code: javax.faces.config_files param-name> /web-inf/faces-config.xml ,/web-inf/faces-beans.xml < / param-value> context-param> A simple example of a navigation rule is actually very simple, let us see the first example:
Code: /pages/inputname.jsp from-view-id> SayHello from-outcome> /PAGES/greeting.jsp to-view-id> navigation-case> Saygoodbye from-outcome> / pages / goodbye .jsp to-view-id> navigation-case> navigation-rule> This code specifies two outputs named /Pages/inputname.jsp View, Sayello and SayGoodbye, they respectively Associated with a specific page. Setting a default output event (Outcome case) is simple, but you can make a lot of changes in this basis. Please see the next code:
Code: /pages/inputname.jsp from-view-id> SayHello from-outcome> /PAGES/greeting.jsp to-view-id> navigation-case> /pages/goDBye.jsp to-view-id> Navigation-case> navigation-rule> This code is very similar to the above code, and the difference is the lack of from-outcome in the second Navigation-Case. This means that all Outcome other than Sayhello will enter the /pages/goodbye.jsp page. Use the model JSF's Navigation model to allow us to utilize mode. These modes have a string that ends with an asterisk "*". See below: Code: / pages / * from-view-id> menu from-outcome> /menu/main_main.jsp to-view-id> navigation-case> info from-outcome> / menu / Info.html to-view-id> navigation-case> navigation-rule> This navigation rule applies to any / pages / start URL similar to / Pages /Exit.jsp page. Note that the asterisk must be placed in the end. For example, a pattern of similar /pages/*.jsp is invalid. Resolving more Than You Matching Rule Now let's take care of how to handle multiple rules in the JSF navigation model. Specifically, see Examples:
Code: / pages / * from-view-id> info from-outcome> /Menu/generalhelp.html to-view-id> navigation-case> navigation-rule> /pages/login.jsp from-view- ID> info from-outcome> /menu/loginhelp.html to-view-id> navigation-case> navigation- Rule> In this case, the second navigation rule, not the previous one, will take effect on /pages/login.jsp, although the page also matches the mode / Pages / * in the first rule. This shows that for a specific from-Outcome, matching more specific rules will take effect. "Global" Outcomes assumes that we need a globalhelp output (OUTCOME) allows you to transfer from any page to the help page /Help/index.html. To achieve this effect, you can take advantage of any of the following two declarations: Code: * from-view-id> globalhelp from-outcome> /menu/generalhelp.html to-view-id> navigation-case> navigation-rule> < From-outcome> globalhelp from-outcome> /menu/generalhelp.html to-view-id> navigation-case> navigation-rule> The first code is on the label The asterisk is used in the from-view-id, and the second break code does not even use the from-view-id label at all. Both can achieve the same effect. However, it is important to note that an empty from-view-id element is not any effect, for example:
Code: from-view-id> globalhelp from-outcome> / menu / generalhelp .html to-view-id> navigation-case> navigation-rule> Rule conflicts This is an interesting issue. If there are two identical from-view-id, it contains from-outcome, but points to different pages. Let's take a look: Code: * from-view-id> globalhelp from-outcome> /menu/generalhelp.html to-view-id> navigation-copy> navigation-rule> * from-view-id > globalhelp from-outcome> /pages/goaway.html to-view-id> navigation-case> navigation-rule > In this case, the last rule will take effect. At the same time, it is also necessary to note that this article mentioned that the JSF configuration information can be placed in multiple files. Thereby the rule that causes conflicts may be located in different profiles, at which point the relevant rules in the last loaded file in the configuration file containing conflict rules should be taken according to the list of JSF profiles in the web.xml file. Separating a navigation rule into several parts of this is the different implementation of the same effect. Try comparison below the following two codes:
Code: /pages/inputname.jsp from-view-id> SayHello from-outcome> /PAGES/greeting.jsp to-view-id> navigation-case> Saygoodbye from-outcome> / pages / goodbye .jsp to-view-id> navigation-case> navigation-rule>
Code: /pages/inputname.jsp from-view-id> SayHello from-outcome> /PAGES/greeting.jsp to-view-id> navigation-case> ... / pages / inputname. JSP from-view-id> Saygoodbye from-outcome> /pages/goDBye.jsp to-view-id> navigation -CASE> The effect is the same as running. However, the second section code display rule declaration can be arbitrarily separated from different locations of the configuration file, or even in different configuration files. You can choose different ways according to your needs. Using Navigation Rules in Action Now, see how to apply the previously learned content to the program. The following is the code that may contain a JSP page: code: Action property value will be used as an output (OUTCOME). Here is another way:
Code: This means calling the getNameBean HelloAction method, the result of the method will become an OUTCOME. Note that the HelloAction must be a public method that returns a value of a string. The above two different ACTION attribute values are subject to a matter of consideration in consideration of a label in the configuration file, which is from the from-action tag, and we have not mentioned in front. Please refer to the following code:
Code: /pages/inputname.jsp from-view-id> SayHello from-outcome> /PAGES/anotherhello.jsp to-view-id> navigation-case> # {getNameBean.HelloAction} from-action> Sayello from-outcome> /pages/hello.jsp to-view-id> navigation-case> navigation-rule> In this code, two Navigation Cases Contains the same from-view-id and from-outcome elements, but the second Navigation Case contains an from-action element. If SAYHELLO is generated by getNameBean.HelloAction, the second Navigation Case will take effect, but the reason is only the same priority except from-Outcome (original: if the self "is determined by getNameBean.HelloAction The Second Navigation Case Will Take Effect, But Only Because OtherWise Both Case Had Equal Precedence.) Review In order to check your understanding of this article. Please see the following example, there is a statement on CommandButton in /pages/inputname.jsp: CODE: The JSF configuration file contains the content: