You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by "Asleson, Ryan" <as...@BIWORLDWIDE.com> on 2008/05/12 20:39:29 UTC

Annotation Validations: Per Method?

 
Hello,
 
I have an Action class that backs a page.  The page has two submit
buttons it:  one that should call methodOne on the Action, and another
that should call methodTwo.
 
Each method has a Validation annotation that validates different fields,
that look something like this:
 
    @Validations(
        requiredStrings={
            @RequiredStringValidator(type=ValidatorType.SIMPLE,
fieldName="firstName", message="please enter first name")}
    )
    public String methodOne() 
    {
        System.out.println("\n\n***** submitFirstName *****");
        return "submitSuccess";
    }
    
    @Validations(
 
requiredStrings={@RequiredStringValidator(type=ValidatorType.SIMPLE,
fieldName="lastName", message="please enter last name")}
    )
    public String methodTwo() 
    {
        System.out.println("\n\n***** submitLastName *****");
        return "submitSuccess";
    }

 
My intent is that the annotation for methodOne should only have the
firstName field as required, while methodTwo should only have lastName
as required.
 
If I submit the form using the button that calls methodOne, I get
validation errors for both firstName and lastName, contrary to my
intent.  Similarly, submitting the form using the button for methodTwo
also produces validation messages for both firstName and lastName.
 
So, my question:  Are the @Validations annotations specific to a method?
It doesn't appear they are, but I just wanted to see if they were and if
I'm doing something wrong.
 
Thank you!!
 
-Ryan
 
 

This e-mail message is being sent solely for use by the intended recipient(s) and may contain confidential information.  Any unauthorized review, use, disclosure or distribution is prohibited.  If you are not the intended recipient, please contact the sender by phone or reply by e-mail, delete the original message and destroy all copies. Thank you.