You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Andy Cheng <an...@pos.st> on 2003/08/04 11:52:09 UTC

Can

Is there anyway of having the code below to return int value? I have
variables that match the datatype in the database, and I really want to
keep it instead of having String methods in the form class and do
conversion everytime I need to read and modified using the get method.
 
<html:select property="IUserType">
<html:option value="1" >Type1</html:option>
<html:option value="2" >Type2</html:option>
<html:option value="0" >Type3</html:option>
</html:select>
 
Andy
 

RE: Can

Posted by Andrew Hill <an...@gridnode.com>.
http will always pass a string parameter so its generally better to make
your action form properties strings as well. The user could have typed
garbage into the form control so the string that is passed might not be
parseable.

Best bet is to add an extra method to your action form that does the
conversion. One approach might be:

public Integer getIUserTypeInteger
{
  try
  {
    return Integer.parseInt( getIUserType() );
  }
  catch(Throwable t)
  {
    return null;
  }
}

Which will return you an Integer, or null if what the user typed wasnt
something that could be converted to an integer.

-----Original Message-----
From: Andy Cheng [mailto:andy@pos.st]
Sent: Monday, 4 August 2003 17:52
To: struts-user@jakarta.apache.org
Subject: Can


Is there anyway of having the code below to return int value? I have
variables that match the datatype in the database, and I really want to
keep it instead of having String methods in the form class and do
conversion everytime I need to read and modified using the get method.

<html:select property="IUserType">
<html:option value="1" >Type1</html:option>
<html:option value="2" >Type2</html:option>
<html:option value="0" >Type3</html:option>
</html:select>

Andy



---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


RE: Can

Posted by Alex Shneyderman <al...@law.columbia.edu>.
Just decalre your IuserType as Integer upon submission Struts will
convert the value.

> -----Original Message-----
> From: Andy Cheng [mailto:andy@pos.st]
> Sent: Monday, August 04, 2003 5:52 AM
> To: struts-user@jakarta.apache.org
> Subject: Can
> 
> Is there anyway of having the code below to return int value? I have
> variables that match the datatype in the database, and I really want
to
> keep it instead of having String methods in the form class and do
> conversion everytime I need to read and modified using the get method.
> 
> <html:select property="IUserType">
> <html:option value="1" >Type1</html:option>
> <html:option value="2" >Type2</html:option>
> <html:option value="0" >Type3</html:option>
> </html:select>
> 
> Andy
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org