Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Java > Java Open Source > Struts
Password Reminder
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Struts section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old September 24th, 2007, 07:16 AM
Registered User
Join Date: Sep 2007
Location: Bangalore, Karnataka, India.
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Validation using Validation Framework

Hi Experts,

  I am facing a problem with Validation Framework. Could you solve my problem. I want to validate a field in which the entered value should not be a negative number.
For Example: if i enter -1 or -2 it should give a validation message. Please give me solution with an example. I tried with min but no use. Thanks in Advance.


Reply With Quote
  #2 (permalink)  
Old January 2nd, 2008, 06:53 AM
Registered User
Join Date: Jan 2008
Location: Bhadrachalam, Andhrapradesh, India.
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts

hi kalyan,

for the same thing i have worked on this couple of weeks back. you need to implement u r own validation rule for this negative integer not to accept . for that u need to write code in validation-rues.xml file,validation.xml and java class for supporting condition. here is the code for u r reference.

   <validator name="myNegativeIf"
                      classname="com.oomc.servicing.icar.web.validator.M yFieldChecks"




 <field property="contract.contractDefault.thresholdAmount "

                <arg0 key="label.contract.threshholdAmount"/>


   // Negative number validation added by vimal 12/18/2007
    public static boolean myNegativeIf(
       Object bean,
       ValidatorAction va,
       Field field,
       ActionErrors errors,
       HttpServletRequest request ) {

       String value = ValidatorUtil.getValueAsString(bean, field.getProperty());
        int value1=0;
        value1= Integer.parseInt(value);
         catch (Exception e) {

      // System.out.println("Value if int not negative is "+value1);
  // System.out.println("value = " + value + "XXXXX");

       //String sProperty2 = field.getVarValue("secondProperty");
       //String value2 = ValidatorUtil.getValueAsString(bean, sProperty2);
  // System.out.println("value2 = " + value2 + "YYYYY");

  if (!GenericValidator.isBlankOrNull(value)) {

               if (value1 < 0) {

                  errors.add(field.getKey(),Resources.getActionError (request, va, field));
                  return false;

          } catch (Exception e) {
             errors.add(field.getKey(),Resources.getActionError (request, va, field));
             return false;

       return true;


Thanks& Regards,

Reply With Quote

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Standalone validation + web form validation morbo Struts 0 August 19th, 2008 04:02 AM
Validation Framework display of user input dayakarb Struts 0 April 20th, 2007 02:31 AM
validation dhaval229 ASP.NET 1.0 and 1.1 Professional 2 February 14th, 2006 02:10 PM
validation dsmportal Pro VB.NET 2002/2003 4 February 10th, 2005 12:26 PM
Validation koneruvijay VS.NET 2002/2003 2 January 20th, 2004 08:00 AM

All times are GMT -4. The time now is 02:52 PM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.