This week's book giveaway is in the Artificial Intelligence and Machine Learning forum.
We're giving away four copies of Zero to AI - A non-technical, hype-free guide to prospering in the AI era and have Nicolò Valigi and Gianluca Mauro on-line!
See this thread for details.
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

Integer type validation thru "validation.xml"

 
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....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
  • 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...
 
This parrot is no more. It has ceased to be. Now it's a tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic