validation in struts2 -
public class admin extends actionsupport implements modeldriven<admindata> { admindata admindata = new admindata(); public admindata getmodel() { return admindata; } @validations(requiredstrings ={ @requiredstringvalidator(type=validatortype.field,fieldname="emailid"), @requiredstringvalidator(type=validatortype.field,fieldname="password")} public string auth() { } @validations(requiredstrings ={ @requiredstringvalidator(type=validatortype.field,fieldname="emailid"), @requiredstringvalidator(type=validatortype.field,fieldname="firstname"), @requiredstringvalidator(type=validatortype.field,fieldname="surname"), @requiredstringvalidator(type=validatortype.field,fieldname="password")} public string create() throws databaseexception { } }
my problem when call create()
method there no problem in validation, when call auth()
method there problem validation because when call auth method goes validation of firstname , surname.
and there getset in admindata.java
by default struts2 validator check validation constraints methods. can configure struts validation constraints related current method. turn on validateannotatedmethodonly
in struts.xml
:
<struts> <package ...> <interceptors> <interceptor-stack name="defaultstack"> ..... <!-- turning per method validation on --> <interceptor-ref name="validation"> <param name="validateannotatedmethodonly">true</param> <param name="excludemethods">input,back,cancel,browse</param> </interceptor-ref> ...... </interceptor-stack> </interceptors> </package> </struts>
see corresponding documentation entry: different validations per method
Comments
Post a Comment