This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
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 Java Interview Guide this week in the Jobs Discussion 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

validator plugin and validate() method needs to use together

kapil patel
Ranch Hand

Joined: Sep 30, 2005
Posts: 33

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:


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

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



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.

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.

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:
subject: validator plugin and validate() method needs to use together
It's not a secret anymore!