Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 10-06-2008, 12:48 AM
Member
 
Join Date: Oct 2008
Posts: 31
Rep Power: 0
piyu.sha is on a distinguished road
Question [SOLVED] Struts 2 Integer Validation not working
I am trying to add Integer validation to the my Struts 2 application.
Here is what I have done

<validators>
<validator type="int">
<param name="fieldName">zipCode</param>
<message>Zip Code needs to be a valid number </message>
</validator>
</validators>

I have already set validate="true" in the <s:form> tag
This is successfully generating the java script code at my JSP. But when I see the generated code. The validation code for my field is


Quote:
<script type="text/javascript">
function validateForm_generateAction() {
form = document.getElementById("generateAction");
clearErrorMessages(form);
clearErrorLabels(form);
// field name: zipCode
// validator name: int
if (form.elements['zipCode']) {
field = form.elements['zipCode'];
var error = "Zip code should be a valid number";
if (field.value != null) {
if (false || false) {
addError(field, error);
errors = true;
}
}
}

return !errors;
}
</script>
Not sure why this code is coming

quote:if (false || false) {


Due to this it will not do validation for this field.

Any clue? Am I doing something wrong here? Please help.
__________________
Live life king size
[
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
]
Bookmark Post in Technorati
Reply With Quote
  #2 (permalink)  
Old 10-06-2008, 12:50 AM
Member
 
Join Date: Oct 2008
Location: US
Posts: 44
Rep Power: 0
kzvi.kzvi.1 is on a distinguished road
Default
looks like the Struts 2 "int" type validator does the range check. It uses IntRangeFieldValidator which is checking for integer range only.

I think its still beta so they may be fixing some issues. It should be working as you are expecting but if this does not work then have a workaround by using regular expression for number validation in your case it should work fine as you have zip code which need not be checked for the range.

Here is a Example Code which demonstrate how you can use regular expression validation for number validation in Struts 2.

____________________________________________
Software Wiki | Interview FAQs | Lucene Search | Oracle | ORM | Struts2 | Job Seeker
__________________
Have fun....

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 10-15-2008, 01:54 AM
Member
 
Join Date: Oct 2008
Posts: 31
Rep Power: 0
piyu.sha is on a distinguished road
Default
I dont know what was wrong with my code, but now i used a different aproach suggested by kzvi.kzvi.1 and it worked.
so just closing the thread.
__________________
Live life king size
[
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
]
Bookmark Post in Technorati
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Struts validation Jack Web Frameworks 3 10-06-2008 12:54 AM
Struts custom Validation ganesan Web Frameworks 0 07-17-2008 01:15 PM
Java mail problem(working in intranet,but not working in iternet) sundarjothi Advanced Java 8 05-28-2008 07:00 AM
log4j not working in struts Manu Web Frameworks 0 03-19-2008 02:54 PM
java validation? lockmac New To Java 3 08-14-2007 04:34 PM


All times are GMT +2. The time now is 05:24 PM.



VBulletin, Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2009, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org