Results 1 to 3 of 3
- 10-06-2008, 12:48 AM #1
Member
- Join Date
- Oct 2008
- Posts
- 31
- Rep Power
- 0
[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
Not sure why this code is coming<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>
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
[Lucene]
- 10-06-2008, 12:50 AM #2
Member
- Join Date
- Oct 2008
- Location
- US
- Posts
- 58
- Rep Power
- 0
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 SeekerHave fun....
JAVA FAQs
- 10-15-2008, 01:54 AM #3
Member
- Join Date
- Oct 2008
- Posts
- 31
- Rep Power
- 0
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
[Lucene]
Similar Threads
-
Struts validation
By Jack in forum Web FrameworksReplies: 3Last Post: 10-06-2008, 12:54 AM -
Struts custom Validation
By ganesan in forum Web FrameworksReplies: 0Last Post: 07-17-2008, 01:15 PM -
Java mail problem(working in intranet,but not working in iternet)
By sundarjothi in forum Advanced JavaReplies: 8Last Post: 05-28-2008, 07:00 AM -
log4j not working in struts
By Manu in forum Web FrameworksReplies: 0Last Post: 03-19-2008, 02:54 PM -
java validation?
By lockmac in forum New To JavaReplies: 3Last Post: 08-14-2007, 04:34 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks