Java Server Faces(JSF)___页面导航
1.导航的三种方式
- url地址导航
- form导航
- 超链接导航
2.导航规则
-
facs-config.xml配置语法文件:
<navigation-rule></navigation-rule> //导航根元素 <from-view-id></from-view-id> //起始导航页面 <navigation-case></navigation-case> //结果匹配语句 <to-view-id></to-view-id> //目标导航页面 <from-action></from-action> //实现网页导航的条件,可以是受管bean的属性和方法,也可以是actionde的属性 <from-outcome></from-outcome> //和<from-action>里面的条件进行匹配,来进行网页的跳转 <redirect/> //网页重定向
-
举例:判断用户输入的数据的长度是否合法?
-
创建UI组件1(index.xhtml ):
<h:form> Eneter your name: <h:inputText id="input_text" value="#{bean.name}" required="true"/> <h:message for="input_text" /> <h:commandButton value="submit" action="#{bean.checkNameLength}" /> </h:form>
-
创建UI组件2(success.xhtml ):
<h:outputText value="用户长度已符合要求!"/>
-
创建UI组件1(error.xhtml ):
<h:outputText value="用户长度不符合要求!"/>
-
创建受管bean
public class bean { private String name; public String getName() { return name; } public void setName(String name) { this.name = name; } public String checkNameLength(){ int length = getName().length(); if(length >= 6){ return "success"; }else{ return "error"; } } }
-
配置facs-config.xml文件;
<navigation-rule> <from-view-id></from-view-id> <navigation-case> <from-action>#{bean.checkNameLength}</from-action> <from-outcome>success</from-outcome> <to-view-id>success.xhtml</to-view-id> </navigation-case> <navigation-case> <from-action>#{bean.checkNameLength}</from-action> <from-outcome>error</from-outcome> <to-view-id>error.xhtml</to-view-id> </navigation-case> </redirect> </navigation-rule>
注:
页面导航也很简单的,只需要弄清楚实现的过程即可。