« Return to Thread: validation with annotation

Re: validation with annotation

by matt.payne :: Rate this Message:

Reply to Author | View in Thread

The current usage of Annotating methods seems broken.  
Its still applying all the validation rules to all methods despite methods having different validation requirements.

The Struts "Zero Config/Annotation/Auto Config needs help"

Hopefully, a sprinkling of sane configuration of inheritance (though xml) will add power, and reduce redundant configuration code.

re: http://jira.opensymphony.com/browse/XW-603

Matt

Ealden Escañan wrote:
On Tue, Mar 11, 2008 at 7:10 AM, xianwinwin <xianwinwin@gmail.com> wrote:
>
> assuming registration is composed of fname, lname, ss, dob and except dob
> all fields are mandatory.
>
> Question: how do I make sure those fields will be input? should I have
> something like:
>
> @RequiredStringValidator(message="Legal Name is missing")
> private setFname(String fn)
>
> on the registration - if so - wouldn't that effect other classes that uses
> registration???
>
> thanks for any input!

Hi xianwinwin,

You can annotate an action method with @Validations and validate from there, ie:

@Validations(
    requiredString = {
        @RequiredFieldValidator(
            type=ValidatorType.FIELD,
            fieldName="registration.fname"
            message="Foo!"
        )
    }
)
public String save() { ... }

http://struts.apache.org/2.x/docs/validation-annotation.html

Admittedly, I used this approach these past few days and found myself
back to validations in XML:
http://blog.ealden.net/2008/03/working-with-struts-2-validators.html

Thanks

--
Ealden Esto E. Escañan
http://blog.ealden.net

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org

 « Return to Thread: validation with annotation