- 我正在通过 java 代码直接构建 MethodExpression。
- 它将表示对带有参数(如 follow)的 bean 方法的调用。
#{bean.method(TheObjectInstance)}
- 该对象是一个简单的自定义 pojo 对象
public class TheObject
{
public String value0 = "value0";
}
- 我们现在创建 MethodExpression,如下所示。
TheObject object = new TheObject();
FacesContext context = FacesContext.getCurrentInstance();
Application application = context.getApplication();
ExpressionFactory factory = application.getExpressionFactory();
//Create method expression
MethodExpression methodExpression = factory.createMethodExpression(
context.getELContext(),
"#{bean.method(" + object + ")}",
null,
new Class<?>[] {TheObject.class});
- 它会生成以下错误。
javax.servlet.ServletException: Encountered "@" at line 1, column 87.
Was expecting one of:
"." ...
"(" ...
")" ...
"[" ...
"," ...
";" ...
">" ...
"gt" ...
"<" ...
"lt" ...
">=" ...
"ge" ...
"<=" ...
"le" ...
"==" ...
"eq" ...
"!=" ...
"ne" ...
"&&" ...
"and" ...
"||" ...
"or" ...
"*" ...
"+" ...
"-" ...
"?" ...
"/" ...
"div" ...
"%" ...
"mod" ...
"+=" ...
"=" ...
我尝试了使用字符串作为参数和布尔对象的相同代码,它工作正常,但使用自定义对象会产生相同的错误,以及如果我们传递一个复杂对象(例如 UIComponent)。
我正在使用 JSF 2.2,欢迎提供任何帮助。