• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Integer type validation thru "validation.xml"

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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....
 
Ankit Pradhan
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The problem is resolved now...
the path of application.properties was not mentioned correctly in strust-config.xml.... by changing it, the application started working fine...
 
What are you doing in my house? Get 'em tiny ad!
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic