Java Mailing List Archive

http://www.junlu.com/

Home » Home (12/2007) » Apache Tomcat »

Re: EL Expressions allowed with Tomcat 5.0.19

Christopher Schultz

2007-08-07

Replies:

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Dimitris,

Dimitris Mouchritsas wrote:
> <fmt:formatNumber type = "currency" groupingUsed = "true" >
>  ${ table_data.package_price +
>  ( road_assistance_2year == '-' ? 0.0 : road_assistance_2year ) +
>  ( comp_offer_data.hasInsurance ? table_data.insuranceValue : 0.0 ) }
> </fmt:formatNumber>
>
> and in Tomcat 6.0.13 it works fine. However in Tomcat 5.0.19 the page
> stops processing and and exception is thrown.

Perhaps the compiler bundled with TC 6 is more forgiving.

> Tomcat complains that he cannot convert String '-' to a
> java.lang.Double.

I assume that table_data.package_price is a double (or Double). You are
adding the result of the ternary operator. The second parameter to the
ternary operator is a double value (0.0). The third one is a String.
Just wrap road_assistance_2year like this:

${ table_data.package_price +
( road_assistance_2year == '-' ? 0.0 :
Double.doubleValue(road_assistance_2year) ) + ...

If you are using localized double values, you'll obviously have to use
another conversion mechanism -- or perhaps you prefer to use something
from your webapp framework of whatever. The point is the same: you can't
add a String to a double. You need compatible data types, so just convert.

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFGuIMZ9CaO5/Lv0PARAqeJAJ97/Xn18Lq8uCgYG4RFzHd8sZFVLACbBWFV
MBsXVhQabw+53yQT+x81oEM=
=4Pk5
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To start a new topic, e-mail: users@(protected)
To unsubscribe, e-mail: users-unsubscribe@(protected)
For additional commands, e-mail: users-help@(protected)

©2008 junlu.com - Jax Systems, LLC, U.S.A.