• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

validator plugin and validate() method needs to use together

 
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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:

 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
********
 
Ranch Hand
Posts: 948
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Danger, 10,000 volts, very electic .... tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic