• Post Reply Bookmark Topic Watch Topic
  • New Topic

Creating custom validators for client side validation in Javascript  RSS feed

Cam Cres
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello guys:
I'm trying to extend the default validators that come with the Struts Validation framework. This is the entry in my validation-rules.xml for my new custom made validator

<!-- My OWN defined validators -->
<validator name="positiveInt"

function validatePositive(form)
return true;


Whenever I do server side validation it works. I can properly see a message stating that the field in question is not a positive integer. I did that in MyOwnValidator class. My problem is when I try to do client side validation. I tried to write a javascript funcion with the same logic that the method that does the server side validation and I passed it within the <javascript> element as in the example above. But I could not get any message or pop up I as got with the default validators. Then I tried returning false or true to experiment results, and nothing ever happened.
What I'm missing. Can someone explain how javascript validation works? Do I have to provide my own javascript code for every custom validator or there is a workaround to that?
I tried viewing the source of the final rendered page and I still could see that my validatePositive(form) exists. Also the message that is supposed to be displayed is there. Then why is nothing happening?

David Newton
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You'll need to show your configuration and the JSP of the form, at least the field you're trying to validate.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!