[jbossseam-issues] [JBoss JIRA] Commented: (JBSEAM-1262) Should be able to customize Hibernate validation messages based on context (by page, or role like Seam component scopes)

Nathaniel Stoddard (JIRA) jira-events at lists.jboss.org
Sat Apr 28 08:32:30 EDT 2007

    [ http://jira.jboss.com/jira/browse/JBSEAM-1262?page=comments#action_12360770 ] 
Nathaniel Stoddard commented on JBSEAM-1262:

I'm not sure how the best way to do this either.  Personally, I don't think we should be specifying error messages (displayed on the presentation tier) in the model -- bad coupling, though not the worst.  The <s:validate> syntax you mentioned would work, but would require one tag for each field being validated.  More people would probably benefit from being able to customize the error messages even when using <s:validateAll>.  I suppose we can ignore @IfInvalid() for now since it is "semi-deprecated".

Since <s:validate> and <s:validateAll> both validate UIInput-bound values, perhaps we can come up with some sort of mechanism where we place a <f:attribute> on the UIInput that species the error message to use for each validation rule.  Ex:

<h:inputText value="#{myBean.socialSecurityNumber}">
    <f:attribute name="msg-pattern" value="#{errors['social-security-number-invalid-pattern']}" />

... I'm just thinking here -- not sure what direction is best.

> Should be able to customize Hibernate validation messages based on context (by page, or role like Seam component scopes)
> ------------------------------------------------------------------------------------------------------------------------
>                 Key: JBSEAM-1262
>                 URL: http://jira.jboss.com/jira/browse/JBSEAM-1262
>             Project: JBoss Seam
>          Issue Type: Feature Request
>    Affects Versions: 1.2.1.GA
>            Reporter: Nathaniel Stoddard
> Currently, each validation specified a single message resource to be used as the error message.  It would be helpful if there was some way to customize the error messages to be used such that in one case "Contact address is required." is displayed, while in others "Billing address is required", for example.  Annotating model classes with validation rules limits the reuse of those classes since the validation messages offer limited flexibility.
> Since validated fields in the domain classes aren't necessarily associated with a UIInput on a page, it would be helpful to have more flexible annotations, such as:
> @MaxLength(messages = {@Message(role='contactForm', value='contact.too_long'), @Message(role='billingForm', value='billing.too_long')})
> private String field;
> Also needed would be some way of indicated to the UIView which 'role' should be used when validation takes place.

This message is automatically generated by JIRA.
If you think it was sent incorrectly contact one of the administrators: http://jira.jboss.com/jira/secure/Administrators.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira


More information about the seam-issues mailing list