Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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: [email protected](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

like image 860
Rajat Gupta Avatar asked Mar 02 '12 13:03

Rajat Gupta


1 Answers

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.

like image 152
BalusC Avatar answered Nov 01 '22 14:11

BalusC