Conditional Navigation Rule in JSF 2.0
来源:互联网 发布:淘宝已发货可以退款吗 编辑:程序博客网 时间:2024/05/29 16:08
JSF 2 comes with a very flexible conditional navigation rule to solve the complex page navigation flow, see the following conditional navigation rule example :
1. JSF Page
A simple JSF page, with a button to move from this page to the payment page.
start.xhtml
##2. Managed BeanA managed bean to provide sample data to perform the conditional checking in the navigation rule.
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import java.io.Serializable;
@ManagedBean
@SessionScoped
public class PaymentController implements Serializable {
private static final long serialVersionUID = 1L;public boolean registerCompleted = true;public int orderQty = 99;//getter and setter methods
}
##3. Conditional Navigation RuleNormally, you declared the simple navigation rule in the “`faces-config.xml`” like this :
start.xhtml
payment
payment.xhtml
With JSF 2, you can add some conditional checking before it move to the payment page, see following :##faces-config.xml
This is equal to the following Java code :
if (from-view-id == “start.xhtml”){
if(from-outcome == “payment”){
if(paymentController.orderQty < 100){ return "ordermore"; }else if(paymentController.registerCompleted){ return "payment"; }else{ return "register"; }
}
}
The code should be self explanatory enough.> Note> In the conditional navigation rule, the sequence of the navigation rule does affect the navigation flow, always put the highest checking priority in the top.##4. TestingDifferent data sets for testing :###Example 1
public class PaymentController implements Serializable {
public boolean registerCompleted = true;public int orderQty = 99;...
When the button is clicked, it hits the "`paymentController.orderQty < 100`" criteria and move to the "`ordermore.xhtml`" page.###Example 2
public class PaymentController implements Serializable {
public boolean registerCompleted = true;public int orderQty = 200;...
When the button is clicked, it hits the "`paymentController.registerCompleted`" criteria and move to the "`payment.xhtml`" page.###Example 3
public class PaymentController implements Serializable {
public boolean registerCompleted = false;public int orderQty = 200;...
When the button is clicked, it failed all the checking criteria and move to the "`register.xhtml`" page.##SuggestionIn JSF 2.0, there is no "else" tag in the conditional navigation rule, wish JSF team can include the "`else`" tag in the future release. For example,
start.xhtml
payment
#{paymentController.orderQty < 100}
ordermore.xhtml
#{paymentController.registerCompleted}
payment.xhtml
register.xhtml
Moreover, It should include the multiple conditional checking as well, like this
start.xhtml
payment
#{paymentController.orderQty < 100} && #{paymentController.xxx}
ordermore.xhtml
#{paymentController.registerCompleted}
payment.xhtml
register.xhtml
“`
Thought…
JSF 2 conditional navigation rule, … quite similar with the Spring Web Flow, right? :)
- Conditional Navigation Rule in JSF 2.0
- Conditional Navigation Rule in JSF 2.0
- Implicit Navigation in JSF 2.0
- JSF “from-action” navigation rule example
- JSF navigation初级应用
- conditional operator in Xcode
- Resources (library) in JSF 2.0
- JSF导航规则(Navigation)
- Use Conditional attribute in C#
- Conditional Compilation In Java @ JDJ
- Configure Managed Beans in JSF 2.0
- Injecting Managed beans in JSF 2.0
- jsf 的导航演示(navigation)
- JSF页面导航(Navigation)配置总结
- Navigation in Silverlight 3
- Navigation Framework In Silverlight
- exception handler in drools rule
- Render_if: Conditional Parts in Nevow Templates
- 65 GCD基本使用
- Conditional Navigation Rule in JSF 2.0
- UITableView简单介绍及其优化
- matlab中的graythresh函数的实例
- [Java] Xfire开发WebService
- Conditional Navigation Rule in JSF 2.0
- 我在CSDN上有了自己的博客
- 如何阅读科研论文
- Android EditText
- Boost.Lockfree官方文档翻译
- javaScript月份从零算起
- JSF “from-action” navigation rule example
- HorizontalScrollView 的使用
- 20150827_tomcat架构_Server.xml详解