-
1. Re: Validation messages
cptnkirk Apr 13, 2007 11:05 AM (in response to nstoddar)Take a look at the message attribute of the Hibernate Validator annotations, they allow per field overrides of the default message. NotNull is still handled by JSF's required=true mechanism, but you have greater flexibility for other field constraints.
-
2. Re: Validation messages
nstoddar Apr 13, 2007 11:11 AM (in response to nstoddar)"CptnKirk" wrote:
Take a look at the message attribute of the Hibernate Validator annotations, they allow per field overrides of the default message. NotNull is still handled by JSF's required=true mechanism, but you have greater flexibility for other field constraints.
I don't want per-field messages. I want to provide some context to the message itself. For example, I would put@NotNull(message="{value.required}") value.required={0} is required.
... and magically be able to inject some value into {0} from somewhere else with "Contact name" or "Billing name", etc instead of just "Value is required." Does that make sense? -
3. Re: Validation messages
cptnkirk Apr 13, 2007 11:33 AM (in response to nstoddar)Yep. It makes sense, it would be nice if you could override the validation message at the <s:validate> level. This has long been a complaint of JSF, and one that I believe will be fixed in JSF 2.0. JBoss will start using the 1.2 RI in 4.2, and that may allow some jsf-ext work to be used, including maybe support for what you're looking for.
Until then, ask Gavin real nice for a <s:validate message="my message"> feature.
Note though that NotNull is a special case in JSF. I believe that JSF will always handle required fields via its required=true mechanism so NotNull isn't a great example of using Hibernate Validator.
Also, Seam provides EL and context aware markup in JSF resource bundles. I don't know if it extends this capability to Hibernate Validator resource bundles, I'd assume not. -
4. Re: Validation messages
pmuir Apr 13, 2007 11:39 AM (in response to nstoddar)Apparently you can do
@Length(min=10,max=20,message="#{messages.lengthValidatorMessage}")
Then you can take advantage of Seam's per view message bundle feature. -
5. Re: Validation messages
nstoddar Apr 13, 2007 11:45 AM (in response to nstoddar)"petemuir" wrote:
Apparently you can do@Length(min=10,max=20,message="#{messages.lengthValidatorMessage}")
Then you can take advantage of Seam's per view message bundle feature.
Do you have a link to some documentation on the "per view message bundle" feature? It sounds useful. In this situation, it wouldn't quite work. My problem is the reuse of fine-grained domain objects, for example an Address. I may have five addresses on a single form, so even if I could customize that message for that view, it would still render the same message for each address instead of "Home address ..." and "Work address ...", etc. -
7. Re: Validation messages
pmuir Apr 13, 2007 12:16 PM (in response to nstoddar)As CptnKirk says, create a JIRA request for overriding the message on the s:validate tag, sounds like the only way to do what you want...
-
8. Re: Validation messages
spambob Apr 13, 2007 5:28 PM (in response to nstoddar)You can do what you want with a PhaseListener. See http://www.oracle.com/technology/pub/articles/masterj2ee/j2ee_wk7.html for more details (the "Adding Meaningful Field References" section) it describes a way doing this by using a PhaseListener that customizes the validation messages based on a parameter supplied by f:attribute tags inside the h:input stuff.
PS: +1 for the <s:validate message="my message"> feature.