Win a copy of Zero to AI - A non-technical, hype-free guide to prospering in the AI era this week in the Artificial Intelligence and Machine Learning forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Paul Clapham
  • Bear Bibeault
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Jj Roberts
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • salvin francis
  • Scott Selikoff
  • fred rosenberger

validation for Inetger type field in Struts

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • 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....
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.empField.integer" 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>

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.empField.integer"

Please help....
 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ankit,

Have you included the entry for this property file in your struts-config.xml. It will be like:

<message-resources parameter="property file name"/>

Please try this and let me know in case of issues.

Regards,

Vivek
 
Can you shoot lasers out of your eyes? Don't look at this tiny ad:
the value of filler advertising in 2020
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic