First of all, I like to thank all the creators and contributors of
play! The Framework is fantastic, it really brings the joy back to web
development with Java!
Here's my little problem:
I have a model class with an embedded Enum:
@Entity
public class Customer extends Model {
@Enumerated(EnumType.STRING)
public Salutation salutation;
....
}
public enum Salutation {
MISS,
MISTER,
}
In the controller I use directly the POJO for the binding:
public static void save(@Valid Customer customer) {
// validation
if(validation.hasErrors()) {
...
This works fine, if the user choose MISS or MISTER, but it is not
possible to bind a Null value. I always get validation errors:
<select id="customer.salutation" name="customer.salutation">
<option></option> <!-- problem -->
<option value="MISS">&{'miss'}</option>
<option value="MISTER">&{'mister'}</option>
</select>
Is there a way to bind these Null values or is this a bug?
Thanks in advance and kind regards
Thilo
> --
> 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.
>
>
> What is the validation error you get?
I get a validation.invalid
I debugged play.data.binding.Binder.java, Line 82ff:
// Enums
if (Enum.class.isAssignableFrom(clazz)) {
if (value == null || value.length == 0) {
return MISSING;
}
return Enum.valueOf(clazz, value[0]);
}
with both variants
<option></option> <!-- problem -->
and
<option value=""></option> <!-- problem -->
The variable "value" (type String[]) contains one empty string
(value.length == 1), because of that, "value" is neither null nor has
length 0 and thus try to return valueOf instead of MISSING.
Regards
Thilo
On Mar 29, 9:55 pm, Guillaume Bort <guillaume.b...@gmail.com> wrote:
I think I just committed a fix for this problem this afternoon. Could you grab the latest 1.0.2 rc2 and try it with it?
In your application.conf you will have to specify:
future.binding.string.value.returnNull=true
If it does not work, please report a bug and I will make sure it works.
Thanks,
Nicolas
The problem remains (1.0.2-RC2 with
future.binding.string.value.returnNull=true). I will file a bug.
IMHO you could fix it, if you test for emptiness of value[0], like:
L95ff in play.data.binding.Binder.java
// Enums
if (Enum.class.isAssignableFrom(clazz)) {
if (value == null || value.length == 0 || value[0].isEmpty()) {
return MISSING;
}
return Enum.valueOf(clazz, value[0]);
}
Thanks for your help!
Kind regards
Thilo
https://bugs.launchpad.net/play/+bug/524689
Regards
Thilo
Thanks
Nicolas