#{bean.function} 和#{bean.function()} 有什么区别?
What is difference between #{bean.function} and #{bean.function()}?
我是 JSF.I 的新人,想知道 JSF/navigation rules.i 有四个页面,索引,p1,p2,p3.When 我正在尝试导航到带有 action="#{bean.gotoP1()}" 的页面,它给出了这样的错误;
"Unable to find matching navigation case with from-view-id '/index.xhtml' for action '#{bean.gotoP1()}' with outcome 'success'"
我的问题很简单;为什么我不能使用 #{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>
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";
}
}
面孔-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>
谢谢....
My question is simple; why can not I navigate with #{bean.gotoP1()} , and i have to remove parenthesis , #{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 中,这种语法是必需的并且 "normal" 是不正确的。此外,导航规则非常像 JSF 1.x-ish。此外,使用 POST 请求执行导航非常像 JSF 1.x-ish。也许你只是在学习和玩耍。没关系,但要了解正确的方法和一些历史,请仔细阅读以下链接:
- Invoke direct methods or methods with arguments / variables / parameters in EL
- Differences between action and actionListener
- JSF implicit vs. explicit navigation
- How to navigate in JSF? How to make URL reflect current page (and not previous one)
- Difference between JSP EL, JSF EL and Unified EL
最后但同样重要的是,our JSF wiki page 是一个很好的起点。
我是 JSF.I 的新人,想知道 JSF/navigation rules.i 有四个页面,索引,p1,p2,p3.When 我正在尝试导航到带有 action="#{bean.gotoP1()}" 的页面,它给出了这样的错误;
"Unable to find matching navigation case with from-view-id '/index.xhtml' for action '#{bean.gotoP1()}' with outcome 'success'"
我的问题很简单;为什么我不能使用 #{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>
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";
}
}
面孔-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>
谢谢....
My question is simple; why can not I navigate with #{bean.gotoP1()} , and i have to remove parenthesis , #{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 中,这种语法是必需的并且 "normal" 是不正确的。此外,导航规则非常像 JSF 1.x-ish。此外,使用 POST 请求执行导航非常像 JSF 1.x-ish。也许你只是在学习和玩耍。没关系,但要了解正确的方法和一些历史,请仔细阅读以下链接:
- Invoke direct methods or methods with arguments / variables / parameters in EL
- Differences between action and actionListener
- JSF implicit vs. explicit navigation
- How to navigate in JSF? How to make URL reflect current page (and not previous one)
- Difference between JSP EL, JSF EL and Unified EL
最后但同样重要的是,our JSF wiki page 是一个很好的起点。