dcsimg
Integer type validation thru "validation.xml"
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Anonymous
Posted On:   Thursday, January 27, 2005 10:31 PM

Hi I am using Struts validator framework checking for the integer type input for a particular field on the JSP. All is working fine, except the message which the validator framework pops when we give a wrong input....although validator stops the flow to the same page but the message which it pops up is coming blank.... the excerpt of Validation.xml is: ... ... // "AddUpdateEmployee" is the action-mapping in Struts-config.xml ... ... and the code for "integer" function in "Validator-rules.xml" is: classname="   More>>


Hi
I am using Struts validator framework checking for the integer type input for a particular field on the JSP.
All is working fine, except the message which the validator framework pops when we give a wrong input....although validator stops the flow to the same page but the message which it pops up is coming blank....



the excerpt of Validation.xml is:
...
...





// "AddUpdateEmployee" is the action-mapping in Struts-config.xml





...
...



and the code for "integer" function in "Validator-rules.xml" is:




classname="org.apache.struts.util.StrutsValidator"
method="validateInteger"
methodParams="java.lang.Object,
org.apache.commons.validator.ValidatorAction,
org.apache.commons.validator.Field,
org.apache.struts.action.ActionErrors,
javax.servlet.http.HttpServletRequest"
depends="required"
msg="errors.integer"
jsFunctionName="IntegerValidations">

<![CDATA[
function validateInteger(form) {
var bValid = true;
var focusField = null;
var i = 0;
var fields = new Array();
oInteger = new employeeActionForm_IntegerValidations();
for (x in oInteger) {
if (form[oInteger[x][0]] != undefined) {
if ((form[oInteger[x][0]].type == 'text' ||
form[oInteger[x][0]].type == 'textarea' ||
form[oInteger[x][0]].type == 'select-one' ||
form[oInteger[x][0]].type == 'radio') &&
(form[oInteger[x][0]].value.length > 0)) {
var iValue = parseInt(form[oInteger[x][0]].value);
if (isNaN(iValue) || !(iValue >= -2147483648 && iValue <= 2147483647)) {
if (i == 0) {
focusField = form[oInteger[x][0]];
}
fields[i++] = oInteger[x][1];
bValid = false;
}
}
}
}
if (fields.length > 0) {
focusField.focus();
alert(fields.join('
'));
}
return bValid;
}
]]>




......
......
vlaues in "application.properties"
....
errors.integer={0} must be an integer.
errors.empId=Employee ID
....
when i give a wrong input although the control remains on the same page but a blank popup occurs.... but what exactly shud happen is the popup shud contain the message specified in the "key" of application.properties which is in this case "errors.integer"

Please help....

   <<Less
About | Sitemap | Contact