[JAVASERVERFACES_SPEC_PUBLIC-1000] Support for Generic Type Managed Beans Created: 10/May/11  Updated: 24/Aug/15  Resolved: 12/Aug/14

Status: Closed
Project: javaserverfaces-spec-public
Component/s: EL
Affects Version/s: 1.1, 1.2, 2.0, 2.1
Fix Version/s: None

Type: Improvement Priority: Trivial
Reporter: josefreire Assignee: Unassigned
Resolution: Won't Fix Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


This is a copy of issue http://java.net/jira/browse/UEL-7. This issue already has a proposed patch.

Text as in UEL-7:
--------------------------------[ begin ]--------------------------------
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()

{ setValue(getValue()+1); return null; }

public String subtract()

{ setValue(getValue()-1); return null; }


This JSF code will not work:
<h:inputText value="#


" />
<h:commandButton action="#


" value="+" />
<h:commandButton action="#


" value="-" />

With this error:
java.lang.ClassCastException: java.lang.String cannot be cast to Java.lang.Integer at genericstest.IntegerTestController.add(IntegerTestController.java:18)

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.
--------------------------------[ end ]--------------------------------

Comment by Ed Burns [ 01/Aug/14 ]

Set priority to baseline ahead of JSF 2.3 triage. Priorities will be assigned accurately after this exercise.

Comment by Ed Burns [ 12/Aug/14 ]

Use CDI instead.

Generated at Sat Mar 25 01:30:33 UTC 2017 using JIRA 6.2.3#6260-sha1:63ef1d6dac3f4f4d7db4c1effd405ba38ccdc558.