[Translation] JSF Navigation File Setting Example

xiaoxiao2021-03-06  39

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 /web-inf/faces-config.xml ,/web-inf/faces-beans.xml < / param-value> A simple example of a navigation rule is actually very simple, let us see the first example:

Code: /pages/inputname.jsp SayHello /PAGES/greeting.jsp Saygoodbye / pages / goodbye .jsp 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 SayHello /PAGES/greeting.jsp /pages/goDBye.jsp 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 / * menu /menu/main_main.jsp info / menu / Info.html 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 / * info /Menu/generalhelp.html /pages/login.jsp info /menu/loginhelp.html 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: * globalhelp /menu/generalhelp.html < From-outcome> globalhelp /menu/generalhelp.html 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: globalhelp / menu / generalhelp .html 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: * globalhelp /menu/generalhelp.html * globalhelp /pages/goaway.html 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 SayHello /PAGES/greeting.jsp Saygoodbye / pages / goodbye .jsp

Code: /pages/inputname.jsp SayHello /PAGES/greeting.jsp ... / pages / inputname. JSP Saygoodbye /pages/goDBye.jsp 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 SayHello /PAGES/anotherhello.jsp # {getNameBean.HelloAction} Sayello /pages/hello.jsp 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:

转载请注明原文地址:https://www.9cbs.com/read-86088.html

New Post(0)