jsf通过EL调用任意方法 [英] jsf Invoking Arbitrary Methods via EL
问题描述
我是JSF的入门者,无法通过EL调用任意方法。
根据我阅读的Java EE 6中包含的2.1版统一表达式语言,它支持调用任意方法。方法并向其传递参数。
我正在使用MyFaces2.0.3,JRE6Up21,Tomcat 6.0.29和Eclipse。
我在facelet中具有以下代码段:
I am starter on JSF and have trouble with invokation of arbitrary methods via EL.
According to what I read version 2.1 of the Unified Expression Language, included in Java EE 6, has support for invoking arbitrary methods and passing arguments to them.
I am using MyFaces2.0.3, JRE6Up21, Tomcat 6.0.29 and Eclipse.
I have the following snippet in a facelet:
<h:form>
<p>
<h:link outcome="NextPage" value="Link for Next Page">
<f:param name="word1" value="hello" />
<f:param name="word2" value="world" />
</h:link>
</p>
</h:form>
以及在方面NextPage.xhtml
and in the facelet NextPage.xhtml
<h:form>
<p>
This is the method invocation #{model.printArgs(param.word1,param.word2)}
</p>
</h:form>
Model
是托管bean(请求范围)具有此方法 printArgs
,该方法返回word1和word2的字符串连接。
Model
is a managed bean(request scoped) that has this method printArgs
that returns a string concatenation of word1 and word2.
@ManagedBean
@SessionScoped
public class Model {
public String printArgs(String word1, String word2) {
String result = "No arguments??????";
if (null != word1 && !word1.isEmpty() && null != word2 && !word2.isEmpty()) {
result = word1+" "+word2;
}
return result;
}
}
当我按网址的链接为 http:// localhost:8080 / RegJSF / faces / NextPage.xhtml?word1 = hello& word2 = world
,但出现错误
When I press the link the url is http://localhost:8080/RegJSF/faces/NextPage.xhtml?word1=hello&word2=world
but I get the error
org.apache.el.parser.ParseException:
在第1行,
第25列遇到了((。期望其中之一:}
... 。 ... [ ...> ... gt ...
< ... lt ...> = ... ge ...
< = ...等
org.apache.el.parser.ParseException: Encountered " "(" "( "" at line 1, column 25. Was expecting one of: "}" ... "." ... "[" ... ">" ... "gt" ... "<" ... "lt" ... ">=" ... "ge" ... "<=" ... etc
如果我删除了# {model.printArgs(param.word1,param.word2)}
加载了NextPage,所以问题出在方法调用上。
这是什么问题?它是配置吗?
注意如果我使用Mojarra2.0.3,同样的问题
有人可以帮忙吗?
If i remove #{model.printArgs(param.word1,param.word2)}
the NextPage is loaded, so the problem is the method invocation.
What is the problem here? Is it configuration issue?
Note Same issue if I use Mojarra2.0.3
Can someone help please?
谢谢!
推荐答案
根据我阅读的Java EE 6中包含的2.1版统一表达式语言,它支持调用任意方法并将参数传递给它们。
According to what I read version 2.1 of the Unified Expression Language, included in Java EE 6, has support for invoking arbitrary methods and passing arguments to them.
我认为你错了。这种支持是在JSP 2.2中引入的(满足JEE6规范是必需的)。
I think you are mistaken. This support was introduced in JSP 2.2 (which is required to meet the JEE6 spec).
来自 JSP 2.2规范:
更改在维护1和维护版本2之间
此版本的主要变化是在
中添加了带有
参数的方法调用EL,例如
#{trader.buy( JAVA)}
。
The main change in this release is the
addition of method invokations with
parameters in the EL, such as
#{trader.buy("JAVA")}
.
由于Tomcat 6是JSP 2.1容器,因此您可以考虑升级到Tomcat 7。
Since Tomcat 6 is a JSP 2.1 container, you might consider upgrading to Tomcat 7.
这篇关于jsf通过EL调用任意方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!