You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by kk...@firstenergycorp.com on 2006/08/03 18:52:48 UTC

displaying Date, BigDecimal as html:text

Hello,

I saw that <bean:write> has a "format" attribute for formatting dates and
dollar values. But I didn't see similar thing for <html:text>. If my bean
has a property called "amount" of type BigDecimal, and I want to display
that as a <html:text> for the user to modify the value, How can I format
it?

Also, if the user leaves the <html:text> field for BigDecimal as blank, I
get an exception (string->BigDecimal conversion exception). So, is the
solution to this is to make all formbean properties to be "String" type?


Thanks,
Kiran


-----------------------------------------
The information contained in this message is intended only for the
personal and confidential use of the recipient(s) named above. If
the reader of this message is not the intended recipient or an
agent responsible for delivering it to the intended recipient, you
are hereby notified that you have received this document in error
and that any review, dissemination, distribution, or copying of
this message is strictly prohibited. If you have received this
communication in error, please notify us immediately, and delete
the original message.


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


Re: displaying Date, BigDecimal as html:text

Posted by Laurie Harper <la...@holoweb.net>.
Puneet Lakhina wrote:
>>
> Also, if the user leaves the <html:text> field for BigDecimal as blank, I
>> get an exception (string->BigDecimal conversion exception). So, is the
>> solution to this is to make all formbean properties to be "String" type?
> 
> you coud do something like
> BigDecimal bigDecimalProperty;
> public setBigDecimalProperty(String value)
> {
> try {
> bigDecimalProperty = new BigDecimal(value);
> }catch(Exception e) {
> bigDecimalProperty = new BigDecimal(somedefaultval);
> }
> }

You could do that, or you could have BeanUtils do it for you. However, 
as long as your form bean property is type BigDecimal rather than 
String, you will be unable to re-display erroneous inputs. In other 
words, if the user types in 'abc', you will not be able to retain that 
value and redisplay it for the user to correct unless you use String. 
That's why form properties should, generally, be String-valued.

L.


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


Re: displaying Date, BigDecimal as html:text

Posted by Puneet Lakhina <pu...@gmail.com>.
>
Also, if the user leaves the <html:text> field for BigDecimal as blank, I
> get an exception (string->BigDecimal conversion exception). So, is the
> solution to this is to make all formbean properties to be "String" type?

you coud do something like
BigDecimal bigDecimalProperty;
public setBigDecimalProperty(String value)
{
try {
bigDecimalProperty = new BigDecimal(value);
}catch(Exception e) {
bigDecimalProperty = new BigDecimal(somedefaultval);
}
}




-- 
Puneet