Implicit Navigation in JSF 2.0
来源:互联网 发布:directx12优化 编辑:程序博客网 时间:2024/06/05 01:59
In JSF 1.2, all the page navigation are required to declare in the “faces-config.xml
” file like this :
...<navigation-rule> <from-view-id>page1.xhtml</from-view-id> <navigation-case> <from-outcome>page2</from-outcome> <to-view-id>/page2.xhtml</to-view-id> </navigation-case></navigation-rule>...
In JSF 2, it treats “outcome
” as the page name, for example, navigate to “page1.xhtml
”, you have to put the “outcome
” as “page1
″. This mechanism is called “Implicit Navigation“, where you don’t need to declare the tedious navigation rule, instead, just put the “outcome
” in the action attribute directly and JSF will find the correct “view id” automatically.
There are two ways to implements the implicit navigation in JSF 2.
1. Outcome in JSF page
You can put the “outcome
” directly in the JSF page.
page1.xhtml
– A JSF page with a command button to move from current page to “page2.xhtml”.
<h:form> <h:commandButton action="page2" value="Move to page2.xhtml" /></h:form>
Once the button is clicked, JSF will merge the action value or outcome, “page2
” with “xhtml
” extension, and find the view name “page2.xhtml
” in the current “page1.xhtml
” directory.
2. Outcome in Managed Bean
Besides, you can also define the “outcome” in a managed bean like this :
PageController.java
@ManagedBean@SessionScopedpublic class PageController implements Serializable { public String moveToPage2(){ return "page2"; //outcome }}
In JSF page, action attribute, just call the method by using “method expression“.
page1.xhtml
<h:form> <h:commandButton action="#{pageController.moveToPage2}" value="Move to page2.xhtml by managed bean" /></h:form>
Redirection
By default, JSF 2 is perform a forward while navigating to another page, it caused the page URL is always one behind :). For example, when you move from “page1.xhtml
” to “page2.xhtml
”, the browser URL address bar will still showing the same “page1.xhtml
” URL.
To avoid this, you can tell JSF to use the redirection by append the “faces-redirect=true
” to the end of the “outcome
” string.
<h:form> <h:commandButton action="page2?faces-redirect=true" value="Move to page2.xhtml" /></h:form>
Note
For simple page navigation, this new implicit navigation is more then enough; For complex page navigation, you are still allow to declare the page flow (navigation rule) in thefaces-config.xml
file.
- Implicit Navigation in JSF 2.0
- Conditional Navigation Rule in JSF 2.0
- Conditional Navigation Rule in JSF 2.0
- jsf in action 笔记:潜藏对象(Implicit Variables)--2008.04.09
- JSF navigation初级应用
- JSF : Variables for implicit JSF EL objects
- Resources (library) in JSF 2.0
- JSF导航规则(Navigation)
- Implicit in Scala
- Explicit, Implicit in FTPs
- Configure Managed Beans in JSF 2.0
- Injecting Managed beans in JSF 2.0
- jsf 的导航演示(navigation)
- JSF “from-action” navigation rule example
- JSF页面导航(Navigation)配置总结
- Navigation in Silverlight 3
- Navigation Framework In Silverlight
- Implicit & Explicit Waits in Selenium
- Http Basic Authentication has some limitations, maybe nginx could do some help...
- Communication Patterns
- IOS 将类的声明,类的定义,主函数分开放的代码。
- 题目:买卖股票的最佳时机 II
- GCD(Grand Central Dispatch)
- Implicit Navigation in JSF 2.0
- Android Studio Git初体验
- C++虚函数的底层实现
- 优化资源配置读后感
- HDU 1251 统计难题-字典树-统计前缀个数
- 题目:买卖股票的最佳时机 III
- Http Basic Authentication 的请求头Authorization的状态保存问题:见‘斜粗下划线’部分说明
- hdu1530 Maximum Clique(求最大团模板题)
- c 语言用递归法倒序字符串