风人园

弱水三千,只取一瓢,便能解渴;佛法无边,奉行一法,便能得益。
随笔 - 99, 文章 - 181, 评论 - 56, 引用 - 0
数据加载中……

JSF--Navigate

JSF中最重要的导航设置
一、静态导航
<h:commandButton label="Login" action="login"/>
通过action返回的字符串,然后比较   from-outcome标签值,如果相同,就返回到   to-view-id  制定的页面
注: view ID strings must start with a /.
二、动态导航
<h:commandButton label="Login" action="#{loginController.verifyUser}"/>
根据action中调用的bean方法返回值来确定显示页面
loginController的验证方法
String verifyUser() {

   if (...)

      return "success";

   else

      return "failure";

}


三、高级导航
Redirection
如果你在to-view-id 后 加redirect元素,则JSP容器即中断当前request请求,并发送一个HTTP redirect 请求到client. 
<navigation-case>
   <from-outcome>success</from-outcome>
   <to-view-id>/success.jsp</to-view-id>
   <redirect/>
</navigation-case>

Wildcards(通配符)
<navigation-rule>
   <from-view-id>/secure/*</from-view-id>
   <navigation-case>
      . . .
   </navigation-case>
</navigation-rule>
只要是在/secure/这个目录下的页面都使用这个导航规则。

所有
<from-view-id>/*</from-view-id>

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

Using from-action
<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>
根据不同的action使用不同的导航规则。

导航算法

The algorithm has three inputs(算法有三个输入):

  • The outcome, that is, the value of an action attribute or the string resulting from the invocation of a method reference. action属性的值或者引用方法的返回结果(字符串类型)

  • The view ID of the current view。当前视图

  • The action, that is, the literal value of the action attribute in the component that triggered the navigation.用以触发导航的组件属性。

The first of two phases is to find the matching navigation-rule, following these steps(第二阶段的第一步就是寻找符合的导航规则).

  • If the outcome is null, return immediately and redisplay the current page.(如果outcome是空,则立刻返回重新显示当前页面)
  • Merge all navigation rules with the same from-view-id value.(合并相同from-view-id的导航规则)
  • Try to find a navigation rule whose from-view-id value matches the view ID exactly. If such a rule exists, take it.
  • Consider all navigation rules whose from-view-id values end with a wildcard suffix, such as secure. For each such rule, check whether the prefix (after removing the *) is identical to the corresponding prefix of the view ID. If there are matching rules, take the one with the longest matching prefix.
  • If there is a rule without a from-view-id, take it.(如果有没有from-view-id的规则,使用)
  • If there is no match at all, redisplay the current page.(如果都没有符合,重新显示当前页面)

The second of two phases is to consider all navigation-case elements in the matching navigation rule (which may consist of several merged navigation-rule elements with matching from-view-id.values).

Follow these steps to find the matching case.

  • If a case has both matching from-outcome and from-action, take it.
  • Otherwise, if a case has matching from-outcome and no from-action, take it.
  • Otherwise, if a case has matching from-action and no from-outcome, take it.
  • Otherwise, if there is a case with neither from-outcome or from-action, take it.
  • If there is no match at all, redisplay the current page.
    Naturally, we recommend that you do not create tricky navigation rules in your own programs. As long as you stay away from wildcards and from-action elements, you won't need to know about the gory details of the navigation algorithm.


 

posted on 2007-04-26 15:23 风人园 阅读(574) 评论(0)  编辑  收藏 所属分类: JSF


只有注册用户登录后才能发表评论。


网站导航: