You can find the full source code for this website in the Seam package in the directory /examples/wiki. It is licensed under the LGPL.
| Online: | 23 Members of 4546 |
| Forum: Seam Users |
06. Aug 2008, 22:20 CET | Link |
I'm using a @Length(min="2",max="5") constraint on a String property. The inputText tag is required="false". Upon submit, no error is reported on the UI, but when it's persisted it throws a validation exception.
My goal is to allow this field to be empty, but if they user fills it in, it should be between 2-5 characters. Is there any way to do this with the standard annotations?
Yup, my validation stuff works fine except for this case. The problem is that it validates on the ui how I want, but not at persist-time. Specifically:
1) nothing filled in, doesn't throw validation error (required="false")
2) filled in, but below or above min and max, throws validation error
3) filled in, and between min and max, doesn't throw validation error
At persist-time, 1) throws an error.
This is a mismatch between JSF and Hibernate validator, JSF sets an empty value as an empty String, not as null (which would pass the validation). Your best bet is to either write a custom length validator that allows this, or write some logic in your backing bean.
Read about how to report a bug.
Check out my book: Hibernate Search in Action
Exactly.
Also, if the field is empty in a JSF/facelet page, "" is set on the model, not null.
Read about how to report a bug.
Yes, this is a big bug in JSF. I have a few TODO curses in my source in places where I translate from "" to null. This should be fixed in JSF 2.0, Pete.
Check out my weblog or have a look at the books I wrote.
I agree with Christian. This behavior is just leaking a web form presentation limitations into the rest of the application. null is a much more sensible value.
Check out my book: Hibernate Search in Action
Ok, I will raise it with the JSF EG.
Read about how to report a bug.