• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

validator plugin and validate() method needs to use together

 
kapil patel
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
kapil patel
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 948
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic