Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jsf-2/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jsf 在MethodExpression.invoke()上找不到方法异常_Jsf_Jsf 2_El_Methodnotfound - Fatal编程技术网

Jsf 在MethodExpression.invoke()上找不到方法异常

Jsf 在MethodExpression.invoke()上找不到方法异常,jsf,jsf-2,el,methodnotfound,Jsf,Jsf 2,El,Methodnotfound,我需要以编程方式调用我的一个支持bean中的方法。我已经看了几个例子,从我所能看到的,这个“应该”起作用 我的代码: UIData data = (UIData)component; fc = FacesContext.getCurrentInstance(); elc = fc.getELContext(); elFactory = fc.getApplication().getExpressionFactory(); mexp = elFactory.createMethodExp

我需要以编程方式调用我的一个支持bean中的方法。我已经看了几个例子,从我所能看到的,这个“应该”起作用

我的代码:

UIData data = (UIData)component;
fc = FacesContext.getCurrentInstance();
elc = fc.getELContext();

elFactory = fc.getApplication().getExpressionFactory();
mexp =
    elFactory.createMethodExpression(elc, data.getValueExpression("value").getExpressionString(), Result.class, new Class[]{});
Object methodResult = mexp.invoke(elc, null);
public Result getCustomer() {
    Result result = null;
    try {
        ...perform database call
    } catch (Exception e) {
        log.error(e);
    }
    return result;
}
“data.getValueExpression(“value”).getExpressionString()返回字符串:

#{reports.customer}
关于我正在呼叫的bean的信息(不知道这些是否相关):
类的托管bean名称是“report”
类在会话范围内
类实现可序列化
我正在调用的方法的访问修饰符是
方法签名中没有参数

我试图调用的方法:

UIData data = (UIData)component;
fc = FacesContext.getCurrentInstance();
elc = fc.getELContext();

elFactory = fc.getApplication().getExpressionFactory();
mexp =
    elFactory.createMethodExpression(elc, data.getValueExpression("value").getExpressionString(), Result.class, new Class[]{});
Object methodResult = mexp.invoke(elc, null);
public Result getCustomer() {
    Result result = null;
    try {
        ...perform database call
    } catch (Exception e) {
        log.error(e);
    }
    return result;
}
堆栈跟踪摘录

SEVERE: javax.el.MethodNotFoundException: Method not found: com.npp.beans.reports.SharebackReportsBean@1ebf0d3.customer()
javax.faces.el.EvaluationException: javax.el.MethodNotFoundException: Method not found: com.npp.beans.reports.SharebackReportsBean@1ebf0d3.customer()
    at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:98)
    at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:98)
    at javax.faces.component.UICommand.broadcast(UICommand.java:311)
    at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:781)
    at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1246)
    at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:77)
    at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:97)
    at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:114)
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:308)
...
Caused by: javax.el.MethodNotFoundException: Method not found: com.npp.beans.reports.SharebackReportsBean@1ebf0d3.customer()
    at com.sun.el.util.ReflectionUtil.getMethod(ReflectionUtil.java:155)
    at com.sun.el.parser.AstValue.invoke(AstValue.java:231)
    at com.sun.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:297)
    at com.npp.business.TableToExcelManager.initExcelWorker(TableToExcelManager.java:247)
    at com.npp.beans.reports.SharebackReportsBean.exportToExcel(SharebackReportsBean.java:439)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at com.sun.el.parser.AstValue.invoke(AstValue.java:234)
    at com.sun.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:297)
    at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:102)
    at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:84)
    ... 26 more
Mar 23, 2011 11:29:34 AM com.sun.faces.lifecycle.InvokeApplicationPhase execute
WARNING: #{reports.exportToExcel}: javax.el.MethodNotFoundException: Method not found: com.npp.beans.reports.SharebackReportsBean@1ebf0d3.customer()
javax.faces.FacesException: #{reports.exportToExcel}: javax.el.MethodNotFoundException: Method not found: com.npp.beans.reports.SharebackReportsBean@1ebf0d3.customer()
    at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:114)
    at javax.faces.component.UICommand.broadcast(UICommand.java:311)
    at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:781)
    at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1246)
    at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:77)
    at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:97)
    at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:114)
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:308)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)

非常感谢您的帮助!

您试图将值表达式视为方法表达式。这是行不通的。值表达式指向getter方法(因此可以省略
get
)虽然方法表达式指向操作方法,但可能需要一个额外的参数。由于您已经有了
ValueExpression
,只需直接从中获取值,而不是试图将其视为
MethodExpression

Result result = (Result) data.getValueExpression("value").getValue(elc);

您不应该更改视图中的EL字符串。只需将其保持为
value=“#{reports.customer}”
。否则它在正常视图中无法工作。

您试图将值表达式视为方法表达式。这是行不通的。值表达式指向getter方法(因此可以省略
get
)虽然方法表达式指向操作方法,但可能需要一个额外的参数。由于您已经有了
ValueExpression
,只需直接从中获取值,而不是试图将其视为
MethodExpression

Result result = (Result) data.getValueExpression("value").getValue(elc);
您不应该更改视图中的EL字符串。只需将其保留为
value=“#{reports.customer}”
。否则它将无法在正常视图中工作