#{bean.method(TheObjectInstance)}public class TheObject
{
public String value0 = "value0";
} 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" ...
"+=" ...
"=" ...发布于 2019-05-17 21:35:17
#{bean.method(object)}的对象的bean方法的#{bean.method(object)},我们应该使用HTML var=object中声明的变量的名称。 <h:form>
<h:datatable var="object" value="#{bean.objects}">
<h:commandbutton value="test" actionlistenner="#{bean.method(object)}"/>
</h:datatable>
</h:form>#{bean.method(object)},则必须生成完整的html元素,包括父html元素(在本例中是包含对象var=object引用的datatable ),然后在MethodExpression代码中生成 //Wrong implementation: the object is converted as object.getClass().toString()
MethodExpression methodExpression = factory.createMethodExpression(
context.getELContext(),
"#{bean.method(" + object + ")}",
null,
new Class<?>[] {TheObject.class});
//Right implementation: we refer to object referenced by the datatable var.
MethodExpression methodExpression = factory.createMethodExpression(
context.getELContext(),
"#{bean.method(object)}",
null,
new Class<?>[] {TheObject.class});https://stackoverflow.com/questions/56125750
复制相似问题