HI
  If u can use struts Validator or not here this is not matter.
In Struts all in put text values takes Strings only. At the time of
populating Action Form use the class org.apache.struts.util.RequestUtils
class.
 In Struts all input values are String type, see the following code how
to assign int variables.

int int_test; 
this is u r declared integer variable in form so this is class level
variable is default value 0 at the time of running app in text field 0
will be displays.
<html:text property="testint" />

 Out put:

 <input type="text" name="testint" value="0">
in case u enter 'ABC' this field Struts populate like this
 
names = request.getParameterNames();
try{
  while (names.hasMoreElements()) {
      String name = (String) names.nextElement();
     
      .
      .
      .
  }
}catch(Exc e){

}
in case any Exception raised it d't assign input value so the default
value int_test=0 as it is
 
- I just add "if myInteger < 1 " in method
validate().
Ok its works fine 

If I define myInteger as String - how do I check that it's a valid
number in the validate() method (without using Validator)?

Private void setMyInteger(String s){
  Try{
     This.Int_test_my_validation=Integer.parseInt(s);
     }catch(NumberFormatException nfe){     
     }

in case int declared form

Private void setInt_test(int i){
This.int_test=i; //if input value is 'ABC' int_test=0 assigned 
}
U no need wary about that validation that is done automatically Struts
in case u declared as int.




Regards
Raghavendra.E
--------------------------
Programmer Analyst

-----Original Message-----
From: Rivka Shisman [mailto:[EMAIL PROTECTED] 
Sent: Monday, July 11, 2005 3:36 PM
To: Struts Users Mailing List
Subject: RE: Using struts forms as Value Objects: your opinion?

Hi again

When you say that validation doesn't work when inserting "ABC" in an
integer field - do you mean when using struts Validator?
I'm not using the Validator - I just add "if myInteger < 1 " in method
validate().

If I define myInteger as String - how do I check that it's a valid
number in the validate() method (without using Validator)?

Thanks
Rivka
************************************************************************
**************************
The contents of this email and any attachments are confidential.
They are intended for the named recipient(s) only.
If you have received this email in error please notify the system
manager or  the 
sender immediately and do not disclose the contents to anyone or make
copies.

** eSafe scanned this email for viruses, vandals and malicious content.
**
************************************************************************
**************************

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to