umi*_*lic 2 navigation jsf jsf-2
我是JSF的新手.我想知道JSF /导航规则的一点.我有四个页面,索引,p1,p2,p3.当我尝试导航到一个页面,其中action ="#{bean.gotoP1()} ",这是错误的;
"无法找到与from-view-id'/index.xhtml'匹配的导航案例,以便对行动'#{bean.gotoP1()}'结果'成功'"
我的问题很简单; 为什么我不能用#{bean.gotoP1()}导航,我必须删除括号#{bean.gotoP1}?
我的代码在下面;
的index.xhtml
<h:body>
<h:form>
<h:commandButton action="#{mybean.gotoP1()}" value="P1"/>
<h:commandButton action="#{mybean.gotoP2()}" value="P2"/>
<h:commandButton action="#{mybean.gotoP3()}" value="P3"/>
</h:form>
</h:body>
Run Code Online (Sandbox Code Playgroud)
mybean.java
@ManagedBean
@RequestScoped
public class Mybean implements Serializable{
private static final long serialVersionUID=1L;
public Mybean() {
}
public String gotoP1(){
return "success";
}
public String gotoP2(){
return "success";
}
public String gotoP3(){
return "positive";
}
}
Run Code Online (Sandbox Code Playgroud)
faces-config.xml中
<navigation-rule>
<from-view-id>/index.xhtml</from-view-id>
<navigation-case>
<from-action>#{mybean.gotoP1}</from-action>
<from-outcome>success</from-outcome>
<to-view-id>/p1.xhtml</to-view-id>
</navigation-case>
<navigation-case>
<from-action>#{mybean.gotoP2}</from-action>
<from-outcome>success</from-outcome>
<to-view-id>/p2.xhtml</to-view-id>
</navigation-case>
<navigation-case>
<from-action>#{mybean.gotoP3}</from-action>
<from-outcome>positive</from-outcome>
<to-view-id>/p3.xhtml</to-view-id>
</navigation-case>
</navigation-rule>
Run Code Online (Sandbox Code Playgroud)
谢谢....
我的问题很简单; 为什么我不能用#{bean.gotoP1()}导航,我必须删除括号#{bean.gotoP1}?
因为EL语法与导航案例不匹配.您在导航案例中定义了#{bean.gotoP1}
而不是#{bean.gotoP1()}
from-action.就那么简单.
那些毫无争议的括号实际上是不必要的.自从引入EL 2.2以来,它们开始在JSF页面上传播,因为平均的EL 2.2感知IDE认为比它更聪明,并且不必要地用括号和所有这些自动完成方法表达式,令人困惑地让JSF首发者认为它们是实际需要.我甚至看到了实际使用的起始者#{bean.getProperty()}
而不是#{bean.property}
输出属性的代码片段,然后javax.el.PropertyNotWritableException
在输入组件中使用时会失败.
请忽略那些无争议的括号.这种语法在JSF中是必需的和"正常"的,这是不正确的.而且,导航规则非常JSF 1.x-ish.此外,使用POST请求执行导航非常JSF 1.x-ish.也许你只是在学习和玩耍.没关系,但要了解正确的方法和一些历史,请仔细阅读以下链接:
最后但同样重要的是,我们的JSF维基页面是一个很好的起点.
归档时间: |
|
查看次数: |
187 次 |
最近记录: |