Straight from the doc located at 
http://java.sun.com/j2se/1.5.0/docs/api/
//obtain a string result of the requested Attribute
returnedParameterName = (java.lang.String)req.getAttribute(ParameterToObtain);
//obtain a Integer object
Integer intObject = new Integer(returnedParameterName);
//obtain the int value ..
int n = intObject.intValue();

HTH
Martin --
*********************************************************************
This email message and any files transmitted with it contain confidential
information intended only for the person(s) to whom this email message is
addressed.  If you have received this email message in error, please notify
the sender immediately by telephone or email and destroy the original
message without making a copy.  Thank you.



----- Original Message ----- 
From: "temp temp" <[EMAIL PROTECTED]>
To: "Struts Users Mailing List" <user@struts.apache.org>
Sent: Friday, July 21, 2006 3:14 PM
Subject: Re: Converting an object to integer


> The object which I want to convert into Integer is a number and can be 
> converted to int, its not a string or a boolean .
> I get this object either from  request attribute , or request parameter or a 
> DAO.
>  If  I  get this  ob ject  from request parameter I  cannot cast it to 
> integer  because I get compilation error stating  that  cannot cast a String 
> to integer in this case do I have to  create a new Integer every time ?
>  Thanks & Regards
>  
>  
> Scott Van Wart <[EMAIL PROTECTED]> wrote:  temp temp wrote:
>> What is the best way to convert an object to an Integer  .If casting dosen't 
>> work?
>>   
> 
> Object probablyAnInteger = ....;
> 
> Integer someInt;
> if ( probablyAnInteger == null || probablyAnInteger.equals( "" ) )
> {
>  someInt = null;
> }
> else
> {
>  try
>  {
>    someInt = new Integer( probablyAnInteger.toString() );
>  }
>  catch ( NumberFormatException e )
>  {
>     // definitely not an integer
>     someInt = null;
>  }
> }
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 
> 
> 
>  
> ---------------------------------
> How low will we go? Check out Yahoo! Messenger's low  PC-to-Phone call rates.

Reply via email to