Enum with custom toString breaks option tag

Bug #588842 reported by Alison Winters
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
play framework
Status tracked in 1.0
1.0
Fix Released
Undecided
Unassigned
1.1
Fix Committed
Undecided
Unassigned

Bug Description

The CRUD tag enumField.html relies on the enum's toString() to set the value for the option tag. This is incorrect and causes the validation of that field to break because enums can't be automatically bound from a custom toString() value, they need to bind from the .name() value.

I am including a patch that fixes this bug and is fully backward compatible with enums that don't have a custom toString(). This works because the default enum toString() always returns name() anyway.

Tags: crud enum
Revision history for this message
Alison Winters (alisonatwork) wrote :
Revision history for this message
Alison Winters (alisonatwork) wrote :

It occurred to me there is also a strong argument to also change "it" to "it.name()" in the following line:

label = messages.get( _property.relation +'.' + it );

That way the lookup value in the messages won't change if the developer changes the behavior of toString().

Revision history for this message
Alison Winters (alisonatwork) wrote :

The fix as committed might not be 100% correct (although it does fix the bug). In my quick patch I just assumed the goal of the name=XXX ord=XXX pairs was to add metadata to the option tag to use in JavaScript. If, in fact, the goal is only to provide some extra information to developer in "view source" then perhaps name=XXX and ord=XXX should remain as they were and the only change should be it -> it.name() for name=it and value=it. See my previous comment also regarding message string/lookup. I think it would be nicer behavior for that line also to change to it.name().

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.