• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Custom Validation

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I want to do custom validation in struts 1.3.10
I have written following code,
validator-rules.xml
--------------
<validator name="ValidateCustomerCode"
classname="com.algo.struts.actions.ValidateHelper"
method="validateCustomerCode"
methodParams="java.lang.Object,
org.apache.commons.validator.ValidatorAction,
org.apache.commons.validator.Field,
org.apache.struts.action.ActionErrors,
javax.servlet.http.HttpServletRequest"
msg="errors.customer"/>

validate.xml
----------------
<field property="customerCode" depends="required,ValidateCustomerCode">
<arg position="0" key="fmCustomerMaster.customerCode"/>
<msg name="ValidateCustomerCode" key="errors.customer" />
</field>

And i have created Java Class ValidateHelper in package com.algo.struts.actions and written static method validateCustomerCode

But this method is not calling .So now validation is perform.
Please let me know i do not get reason .Do i need to change anything in Form Validation method also ?
 
deep kulkarni
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please let me know about above post ASAP.
 
Ranch Hand
Posts: 2908
1
Spring Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Have you got any exception/error, please look at the logs regarding this validation.xml. Also look at this link, its client side JS custom validation example which might help you.
 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Check whether you have validate="true" in your action? For validation to happen the corresponding action tag should have validate="true"

Regards
Valli
 
deep kulkarni
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for your reply ,
I had validate="true" in struts-Config.xml.
I am not getting one point here how method configure in validation-rule.xml shall be called. Does it required to call explicitly from validate method of form? Is this any relation between validate method of form and xml file ?
I have only written static method as mentioned above and that i configure in validation-rule.xml & validate.xml .Does this sufficient for custom validation ?
 
Sagar Rohankar
Ranch Hand
Posts: 2908
1
Spring Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

deep kulkarni wrote: Is this any relation between validate method of form and xml file ?


No, validate method doesn't know anything about your xml files. Its straightforward overridden method, which can be used for server side form validation in the Action Form itself.

deep kulkarni wrote: I have only written static method as mentioned above and that i configure in validation-rule.xml & validate.xml .Does this sufficient for custom validation ?


Interestingly, I didn't find any good example on "How To Do Plugable Validation" on Struts site, only thing they given is : Pluggble Validation

May be you configured correctly, but its not getting called because of the exception/error, have you seen log files ?
 
deep kulkarni
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Sagar,
We have not implemented logger or anything to log exception/error. But on console i have not seen any exception ,I have put debug on this class static method but it is not calling this method.I have gone through various material and done same accordingly but its not getting call. Please guide me for any custom validation example for struts 1.3.10.
 
Sagar Rohankar
Ranch Hand
Posts: 2908
1
Spring Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

deep kulkarni wrote:Hi Sagar,
We have not implemented logger or anything to log exception/error.


I'm asking about Tomcat logs (or server logs, If you're not using Tomcat)
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic