Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 10-06-2008, 02:48 AM
Member
 
Join Date: Oct 2008
Posts: 18
piyu.sha is on a distinguished road
[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
Sponsored Links
  #2 (permalink)  
Old 10-06-2008, 02:50 AM
Member
 
Join Date: Oct 2008
Location: US
Posts: 40
kzvi.kzvi.1 is on a distinguished road
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, 03:54 AM
Member
 
Join Date: Oct 2008
Posts: 18
piyu.sha is on a distinguished road
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
Sponsored Links
Reply


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

vB 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 02:54 AM
Struts custom Validation ganesan Web Frameworks 0 07-17-2008 03:15 PM
Java mail problem(working in intranet,but not working in iternet) sundarjothi Advanced Java 8 05-28-2008 09:00 AM
log4j not working in struts Manu Web Frameworks 0 03-19-2008 04:54 PM
java validation? lockmac New To Java 3 08-14-2007 06:34 PM


All times are GMT +3. The time now is 09:02 AM.


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