Hi all,
I have a simple model Flight which has a property "origin" which is a
simple enum of type City.
@Entity
public class Flight extends Model {
@Required
@Enumerated(EnumType.STRING)
public City origin;
}
I would like to present the user with a blank choice which would
nullify this property.
So either
#{field 'flight.origin'}
#{select
field.name, id:'origin', value:flight.origin}
#{option}-Choose-#{/option}
#{list cities, as:'city'}
#{option city}${city.label}#{/option}
#{/list}
#{/select}
#{/field}
or
#{field 'flight.origin'}
<select id="origin" name="${
field.name}">
<option value="" ${flight.origin == null ? 'selected' : ''}>-
Choose-</option>
#{list cities, as:'city'}
<option value="${city}" ${flight.origin == city ? 'selected' :
''}>${city.label}</option>
#{/list}
</select>
#{/field}
However, in both cases, when editing an instance of Flight which has
this value populated initially, selecting the blank option doesn't get
bound.
I've traced the problem to Binder:
if (Enum.class.isAssignableFrom(clazz)) {
if (value == null || value.length == 0 ||
StringUtils.isEmpty(value[0])) {
return MISSING;
}
return Enum.valueOf(clazz, value[0]);
}
And then subsequently BeanWrapper:
Object value = Binder.bindInternal(name, prop.getType(),
prop.getGenericType(), params, newPrefix);
if (value != Binder.MISSING) {
prop.setValue(instance, value);
}
As the field value submitted is blank, the Binder reports it as
MISSING and the BeanWrapper skips it.
What is the recommended way of clearing an Enum other than creating an
explicit Enum value to represent blank or providing my own Binder/
Plugin implementation.
Any help provided is much appreciated.
Thanks,
dave
--
You received this message because you are subscribed to the Google Groups "play-framework" group.
To post to this group, send email to
play-fr...@googlegroups.com.
To unsubscribe from this group, send email to
play-framewor...@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/play-framework?hl=en.