JSF & Support for Generic Types... Again...

From: Freire, Jose Luis (PT - Lisbon) <"Freire,>
Date: Tue, 26 Apr 2011 14:46:11 +0000

Hi everyone! It's me again with this 2 year old feature request.

This issue had been addressed in project UEL, however, it's been pretty much ignored, so I'm trying to raise some awareness in the benefits of this request.

The issue is documented here (, and it has a proposed patch.

Here is the description:

Currently JSF doesn't support generic types in managed beans.

When we have a class like:

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(

The problem is with section 2.2.7 of the specification (1.1):
The provided property will first be coerced to a String. If there is a BeanInfoProperty for this property and there were no errors retrieving it, the propertyType of the propertyDescriptor is returned. Otherwise, a PropertyNotFoundException is thrown.
The propertyType of a generic property is Object.class, that gets coerced to String.class, and we get the ClassCastException.

The proposed patch is against version 1.1 because the SVN links in the project page are broken, and to be honest, I would like to see some interest it this feature before investing the time to make the updated patch.


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 423 834 | Fax: +(351) 210 422 950 |

Please consider the environment before printing.

Deloitte refers to one or more of Deloitte Touche Tohmatsu Limited, a UK private company limited by guarantee, and its network of member firms, each of which is a legally separate and independent entity. Please see for a detailed description of the legal structure of Deloitte Touche Tohmatsu Limited and its member firms.
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.