Is JSF incompatible with generics?

From: Freire, Jose Luis \(PT - Lisbon\) <"Freire,>
Date: Tue, 9 Jun 2009 14:56:28 +0100

Using JSF 1.2.12, Facelets 1.1.14, Tomcat 6.0.18.

I'm not sure where to open this bug, since I'm not sure if it's JSF, Facelets, or EL related.

If we have this simple class:
public class GenericsTestController<E extends Object> {

       private E value;

       public E getValue() {
              return value;

       public void setValue(E value) {
              this.value = value;

And we have this class to use as a managed bean (integerTest):
public class IntegerTestController extends GenericsTestController<Integer> {

       public String add() {
              return null;
       public String subtract() {
              return null;

This JSF code will not work:
       <h:inputText value="#{integerTest.value}" />
       <h:commandButton action="#{integerTest.add}" value="+" />
       <h:commandButton action="#{integerTest.subtract}" value="-" />

With this error:
java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Integer
       at genericstest.IntegerTestController.add(
       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
       at sun.reflect.NativeMethodAccessorImpl.invoke(
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(
       at java.lang.reflect.Method.invoke(
       at org.apache.el.parser.AstValue.invoke(
       at org.apache.el.MethodExpressionImpl.invoke(
       at com.sun.facelets.el.TagMethodExpression.invoke(
       at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(
       at com.sun.faces.application.ActionListenerImpl.processAction(
       at javax.faces.component.UICommand.broadcast(
       at javax.faces.component.UIViewRoot.broadcastEvents(
       at javax.faces.component.UIViewRoot.processApplication(
       at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(
       at com.sun.faces.lifecycle.Phase.doPhase(
       at com.sun.faces.lifecycle.LifecycleImpl.execute(
       at javax.faces.webapp.FacesServlet.service(
       at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(
       at org.apache.catalina.core.ApplicationFilterChain.doFilter(
       at org.apache.catalina.core.StandardWrapperValve.invoke(
       at org.apache.catalina.core.StandardContextValve.invoke(
       at org.apache.catalina.core.StandardHostValve.invoke(
       at org.apache.catalina.valves.ErrorReportValve.invoke(
       at org.apache.catalina.core.StandardEngineValve.invoke(
       at org.apache.catalina.connector.CoyoteAdapter.service(
       at org.apache.coyote.http11.Http11Processor.process(
       at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(

In fact, it fails with the same error even if we override getValue and setValue on IntegerTestController.

The only workaround is not to extend from GenericsTestController and implement the "value" property as Integer in the IntegerTestController.

Help anyone?

José Freire
Consulting - Financial Services Industry
Deloitte Consultores, S.A.
Deloitte | Edifício Atrium Saldanha, Praça Duque de Saldanha, 1 - 7º, 1050-094 Lisboa, Portugal
Tel/Direct: +(351) 210 422 500 | Fax: +(351) 210 422 950 |

Please consider the environment before printing.

Deloitte refers to one or more of Deloitte Touche Tohmatsu, a Swiss Verein, its member firms, and their respective subsidiaries and affiliates. As a Swiss Verein (association), neither Deloitte Touche Tohmatsu nor any of its member firms has any liability for each other's acts or omissions. Each of the member firms is a separate and independent legal entity operating under the names "Deloitte," "Deloitte & Touche," "Deloitte Touche Tohmatsu," or other related names. Services are provided by the member firms or their subsidiaries or affiliates and not by the Deloitte Touche Tohmatsu Verein.
Privileged/Confidential Information may be contained in this message. If you are not the addressee indicated in this message (or responsible for delivery of the message to such person), you may not copy or deliver this message to anyone. In such case, you should destroy this message and kindly notify the sender by reply email. Please advise immediately if you or your employer do not consent to Internet email for messages of this kind. Opinions, conclusions and other information in this message that do not relate to the official business of my firm shall be understood as neither given nor endorsed by it.