I recently tried to upgrade to Trinidad 1.2.10, but hit a problem with my
use of selectOneChoice components. Here's an example of a snippet in
question:
<tr:selectOneChoice label="Location"
id="location" value="#{pageFlowScope.incomeBean.location}"
showRequired="true"
requiredMessageDetail="Location must be specified."
valueChangeListener="#{pageFlowScope.incomeBean.locationChangeListener}"
onchange="submit()" immediate="true"
disabled="#{pageFlowScope.incomeBean.fieldReadOnly}">
<f:selectItems
value="#{listOfValuesFactoryBean.locationLOVBean.selectItems}"/>
</tr:selectOneChoice>
There is a converter registered for the type of the property being edited
(i.e. incomeBean.location). The selectItems each have a label and they each
have a value which is of the precise type to be returned to the property
being edited.
Previous to 1.2.9, the behaviour would be that the set method of the backing
bean would be invoked with an object of the correct type (I believe it did
this without invoking the converter). With 1.2.10, it now seems to convert
the object to a string (using it's toString() method) and then passes the
resulting value to the converter. Unfortunately, in this case, the
toString() method does not return a value that complies with the format
being used for the labels in the selectOneChoice and, hence, the converter
does not recognize it.
I had a browse of the trinidad source control system and it looks like a
change was made to the method _convertIndexedSubmittedValue() of class
org.apache.myfaces.trinidadinternal.renderkit.core.xhtml.SimpleSelectOneRenderer
as follows:
---
myfaces/trinidad/trunk_1.2.x/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/SimpleSelectOneRenderer.java
2008/06/28 16:57:29 672549
+++
myfaces/trinidad/trunk_1.2.x/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/SimpleSelectOneRenderer.java
2008/09/11 21:11:23 694485
@@ -215,9 +215,18 @@
SelectItem item = selectItems.get(index);
if (item != null)
- return item.getValue();
+ {
+ Object converted = item.getValue();
+ if (converter != null)
+ {
+ converted = converter.getAsObject(context, component,
converted.toString());
+ }
+ return converted;
+ }
else
+ {
return null;
+ }
}
I'm no expert on JSF so I'm not sure whether the 1.2.10 behaviour is more
correct than the 1.2.9 behaviour, but can someone clarify what the precise
behaviour should be? If 1.2.10 has regressed then I will log a bug with
details, otherwise I will need to adapt my use of converters to cope with
1.2.10.
Thanks
F.