Details
Description
After doing a bit of research, I'm convinced a problem occurs when SelectItem.itemValue is an EJB. Given that 1.1.3 and the RI (1.2_04) do not have this problem, I suggest the current implementation be changed. If I'm wrong, please help me understand. Otherwise, I'll submit a change request.
JSP contents:
<h:selectOneMenu id="client" value="#
" required="true">
<f:converter converterId="x.y.ProjectTypeConverter"/>
<f:selectItem itemValue="" itemLabel="--- Select Project Type---"/>
<f:selectItems value="#
"/>
</h:selectOneMenu>
Where ProjectTypeConverter returns null for "" on input and myPage.projectTypeList is a list of SelectItem created in the following manner:
ArrayList projectTypes = new ArrayList( projectTypeHome.findAll() );
for( int i = 0; i < projectTypes.size(); i++ )
Note that the SelectItem.itemValue is an EJB.
The intent is to force the user to select a value from the list. If no action is taken by the user, generate an error. This is directly analogous to a Tomahawk example, except the values are EJB's.
The problem:
This worked fine under MyFaces 1.1.3 and appears that it would work under RI 1.2_04. Under release 1.1.5, however, a ClassCastException occurs during the validation phase, but only if a list item is selected and the item is an EJB.
Analysis (based on 1.1.5 release):
During the validation phase, UISelectOne.validateValue is invoked with the selected EJB. This causes the following lines in _SelectItemsUtil.matchValue() to be invoked:
[item is class SelectItem]
Object itemValue = item.getValue();
if (value==itemValue || value.equals(itemValue))
This is fine for the SelectItem values that are EJB's, but not for "". Since EJB equality requires identity, the EJB equals() method calls isIdentical() and immediately encounters an exception casting to EJBLocalObject (code here from JBoss 4.0.4GA LocalProxy):
Boolean isIdentical(final Object a, final Object b)
{
final EJBLocalObject ejb = (EJBLocalObject)a;
Boolean isIdentical = Boolean.FALSE;
if( ejb != null )
return isIdentical;
}
Possible solution:
In _SelectItemsUtil.matchValue() change the lines above to:
[item is class SelectItem]
Object itemValue = item.getValue();
if (value==itemValue || ( itemValue != null && itemValue.equals(value)))
Note: The attached test files attempt to recreate the exception with a POJO rather than an EJB.