| Author |
validation fron both ActionForm and struts inbuilt validtaion
|
Nishita Jain
Ranch Hand
Joined: Mar 30, 2006
Posts: 97
|
|
hi, can i use validation fron both ActionForm and struts inbuilt validtaion. i mean in struts config i have validation=true so i will get some validaion on that. at the same time i also want to use the errors which i get from my validate method of Actionfrom bean. At a time only one validation works can i use both validations at same time. as i dont want to use Custom validations. we are writing ActionErrors validate(ActionMapping mapping, HttpServletRequest request) { so is there a way out to find errors from mapping. Thank you in advance. Nishita
|
Nishita
|
 |
Satish SN
Ranch Hand
Joined: Apr 19, 2005
Posts: 70
|
|
Hi Nishita, First of all are u clear with validate() method in ActionForm and the validate = true attrib value in struts-config value. reason being both mean the same. it works like this if in Action tag u mention validate = 'true' then the corresponding ActionForms validate() method is called where u would implement ur validation logic which returns ActionErrors . with this i think if u mention validate = 'true' then only ur validate method defined in the ActionForm is invoked other wise it does not invoke it at all.
|
Satish SN<br />SCJP 1.4 & SCWCD 1.4
|
 |
Nishita Jain
Ranch Hand
Joined: Mar 30, 2006
Posts: 97
|
|
hello, i might have not describe myself well. what i did was in struts-config file i wrote validation=true an in validation.xml i have written <form name="QuestionBean"> <field property="questionText" depends="required,maxlength"> <arg0 key="prompt.questionText"/> <arg1 key="${var:maxlength}" name="maxlength" resource="false"/> <var> <var-name>maxlength</var-name> <var-value>50</var-value> </var> </field> </form> so it will do validation even if i dont write write validate methis in actionForm page. so now i want to do validation using both validation.xml and Actionfrom validate method. am i clear now? Thanks -Nishita
|
 |
Brent Sterling
Ranch Hand
Joined: Feb 08, 2006
Posts: 948
|
|
Sure you can do this. In your form should extend a class such as ValidatorForm. Override the validation method and either call super.validate some place in your code. Such as this: - Brent
|
 |
Nishita Jain
Ranch Hand
Joined: Mar 30, 2006
Posts: 97
|
|
hello Brent, Thanks for solving my problem -Nishita
|
 |
 |
|
|
subject: validation fron both ActionForm and struts inbuilt validtaion
|
|
|