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:
...
...
<form-validation>
<formset>
<form name="/AddUpdateEmployee">
// "AddUpdateEmployee" is the action-mapping in Struts-config.xml
<field property="empId" depends="integer">
<arg0 key="errors.empId" resource="true"/>
</field>
...
...
and the code for "integer" function in "Validator-rules.xml" is:
<validator name="integer"
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">
<javascript>
<![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('\n'));
}
return bValid;
}
]]>
</javascript>
</validator>
......
......
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....