File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Struts and the fly likes validator plugin and validate() method needs to use together Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "validator plugin and validate() method needs to use together" Watch "validator plugin and validate() method needs to use together" New topic
Author

validator plugin and validate() method needs to use together

kapil patel
Ranch Hand

Joined: Sep 30, 2005
Posts: 33
Hi,

I have searched this problem on Internet and java ranch forum. I have not luck so far. Please give your feedback where I am making mistake. Thanks in advance.

I am using validator framework for some validations. However, I want to use separate validation for few validations. When I use separately, they work fine. However, when I use form validate() method, validator framework validations does not work.

My code is below:

validation.xml

<?xml version="1.0" encoding="UTF-8"?>

<form-validation>
<formset>
<form name="volunteerForm">
<field property="txtUserName" depends="required">
<arg0 key="prompt.userName" />
</field>
<field property="txtPassword" depends="required">
<arg0 key="prompt.password" />
</field>
<field property="txtConfirmPassword" depends="required">
<arg0 key="prompt.confirmPassword" />
</field>
<field property="txtFName" depends="required">
<arg0 key="prompt.firstName" />
</field>
<field property="txtPhone" depends="integer">
<arg0 key="prompt.phone" />
</field>
<field property="txtMobile" depends="integer">
<arg0 key="prompt.mobile" />
</field>
<field property="txtEmail" depends="email">
<arg0 key="prompt.email" />
</field>
<field property="txtBirthDate" depends="date">
<arg0 key="prompt.birthDate" />
</field>
</form>

</formset>

</form-validation>


code for validate method of form:

Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
In order for the Validation framework to work, your form bean must extend ValidatorForm. It is the validate method in VaidatorForm that performs the framework validations. If you override the validate() method, you override the framework validations with your validations, making it so the framework validations are no longer performed.

You can get around this by replacing your current code with something like the following:

This way you populate the ActionErrors object with whatever errors the validation framework finds, and then add whatever errors you find in your logic.


Merrill
Consultant, Sima Solutions
kapil patel
Ranch Hand

Joined: Sep 30, 2005
Posts: 33
Thank you very much. It is working perfactly fine.

Howeover, I have got one problem. I was trying for very long but still no success.

I am filling up various selection optins from database using action (VolunteerRegiInitAction) and forwarding to jsp page (volunteerRegistration.jsp). From there, it submit for another action (). Everything is working fine. However, when I submit form with some wrong validated value, it shows errors - that is fine.

However, after showing errors, when I reset page using <html:reset /> it reset to previous submitted value. Please can you give idea if you know where I am wrong.





********
struts-config.xml
********
Brent Sterling
Ranch Hand

Joined: Feb 08, 2006
Posts: 948
What do you expect the reset button to do? This button resets all the fields on the form to what they were when the page was displayed. In your case, this would be the values when the page was shown after the validation error.

- Brent
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: validator plugin and validate() method needs to use together
 
Similar Threads
Validation framework issue in struts2
Struts Validation not working
Struts validator question
Struts 1.1.3 validator framework not working
errors messages from ActionForm validate are not displaying