• 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 Validations in Struts Validator Framework?

 
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The function defined in the custom validation class gets called, but somehow i am not getting the error message when i voilate the validation.

Validation.xml
============================


validator-rules.xml
============================



SalesRepExistanceValidator class (my custom validation)
=======================================================


Keys defined in the property file
==================================


Kindly help !!!
[ November 16, 2006: Message edited by: Manish Sachdev ]
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Change

to

The string argument for the ActionMessage constructor should be a message key, not the actual text of the message.
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Have you checked in struts-config.xml
<action-mapping>
<action> the attribute should specify validate is true
and i want to know how declared onSubmit in jsp/html.

Thanks & Regards
Ravi.
 
Ranch Hand
Posts: 948
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It sounds a lot like the issue that Ja vardhan is asking about (in the three active threads). Is errors coming in null? If so then I cannot imagine that the line of code that creates a new ActionErrors object is going to work. The calling method will never see the object that you created (that is just the way that parameter work in Java).

What version of Struts are you using?

- Brent
 
Brent Sterling
Ranch Hand
Posts: 948
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I would be tempted to switch over to using ActionMessages. I took a look at the code for the "required" validation and here is the code for Strut 1.3:


- Brent
 
M Sharma
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for your valuable inputs folks!!!

Brent you pointed it right, i receive errors object as null in this method. I think ideally it should be the one which is present in request.

Apart from this custom validation, all other standard validations are working.

The version of struts being used is 1.2.9

I have made some changes, which are marked in bold in the code below:

My Validator Class i.e. SalesRepExistanceValidator
==================================================



Output on the console as per the SOPs is
=========================================
folder matched is >> 101 (Alan Rego)
errors object is >> null
field key is >> empNumber

As we can see, the error object received in validateSalesRepExistance method is null.

Kindly help, if you have any clues on how to get this working. I am trying this from yesterday, but not able to get it.

Thanks in Advance...
 
M Sharma
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks folks!!

At last i got the solution

It seems that later versions of struts, have started populating ActionMessages instead of ActionErrors in case of any validation being voilated. I just replaced the ActionErrors parameter in my validate method to ActionMessages and it worked

I have highlighted the changes in bold.

validation-rules.xml
=======================================




SalesRepExistanceValidator class (Changes done in signature only, ActionErrors replaced by ActionMessages)
=======================================================



I hope it helps others facing a similar problem
[ November 17, 2006: Message edited by: Manish Sachdev ]
 
reply
    Bookmark Topic Watch Topic
  • New Topic