Passing enum value as parameter to bean method from JSF pages fail after migrating to tomcat

回眸只為那壹抹淺笑 提交于 2019-12-19 03:38:14

问题


I recently migrated my JSF app(using primefaces) from glassfish 3.1 to tomcat7 server. Previously passing the enum value as string to managed bean methods through actionlistener attribute worked(without the need for a converter to convert string to enum) but now it fails with javax.el.MethodNotFoundException.

JSF page:

<h:form>
   <h:outputLabel value="Title"/><br/>
   <p:inputText value="#{lobController.current.title}"/>

   <p:commandButton action="#{lobController.create('CAR')}" value="Post"/>
</h:form>

Mangaged bean method

public void create(Type type) {
  ...
}

Log messages:

javax.el.MethodNotFoundException: /_newLOB.xhtml @85,111 action="#{lobController.create('CAR')}": Method not found: d432.xontrollers.LOBController@15b2cec.create(java.lang.String) at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:110) at javax.faces.component.UICommand.broadcast(UICommand.java:315) at javax.faces.component.UIData.broadcast(UIData.java:1093) at javax.faces.component.UIData.broadcast(UIData.java:1093) at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:794) at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1259) at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81) at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101) at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118) at javax.faces.webapp.FacesServlet.service(FacesServlet.java:593) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:304) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) at org.primefaces.webapp.filter.FileUploadFilter.doFilter(FileUploadFilter.java:79) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)


Edit

This starts working if I change the managed bean method as follow:

public void create(String type) {
     Type type = Type.valueOf(type);
     ...
}

Using Primefaces 3.1 with JSF 2.1.6 on Tomcat 7.0.14


回答1:


It's a bug in Tomcat's EL implementation. I've reported it for you: issue 52970. Hopefully they aren't as picky on this as on my previous reports.

Until they get it fixed, your best bet is to drop a copy of Glassfish 3's EL 2.2 implementation JAR file in your webapp's /WEB-INF/lib and tell Mojarra to use it instead by the following entry in web.xml:

<context-param>     
    <param-name>com.sun.faces.expressionFactory</param-name>
    <param-value>com.sun.el.ExpressionFactoryImpl</param-value>   
</context-param>

Update: the ticket mentions that it's fixed and it will be in 7.0.27 and onwards.



来源:https://stackoverflow.com/questions/9534130/passing-enum-value-as-parameter-to-bean-method-from-jsf-pages-fail-after-migrati

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!