You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Jason Long <ja...@supernovasoftware.com> on 2005/10/03 09:54:59 UTC

Problem with formatKey using java.lang.Double that works with primitive double

I have been using Struts extensively in my applications for several years
and recently noticed some strange behavior.   I format numbers and dates as
follows:

 

<bean:write name="inventoryStatusForm" property="released.numTons"
formatKey="format.decimal.3" />

 

This is used in hundreds of places throughout my application and works fine
if the value is java.lang.Double, but recently this started acting strangely
for no reason.

 

It will not format some values unless I declare them as primitive values.
As soon as I change numTons on the release object it formats fine.  I do not
understand what is going on as I always use java.lang.Double and never use
the primitive type in my objects.  Why all of a sudden would this work in
some places and not in others?

 

Thank you for your time,

 

Jason Long

CEO and Chief Software Engineer

BS Physics, MS Chemical Engineering

http://www.supernovasoftware.com 

 


Re: Problem with formatKey using java.lang.Double that works with primitive double

Posted by Kishore Senji <ki...@gmail.com>.
> It will not format some values unless I declare them as primitive values.
> As soon as I change numTons on the release object it formats fine.
>

Interesting. The <bean:write/> tag will use the PropertyUtils.getProperty()
to the value for that property and then format it. The getProperty() of
PropertyUtils returns a java.lang.Object and so even if the property is
defined as a primitive the corresponding Object wrapper will be given back
for formatting. The <bean:write/> will format unless the value from the
getProperty() is resolved to a java.lang.String. So, I think it should
behave the same if you use java.lang.Double or a primitive double.

I would try from a test-case what the type of the object that is being
returned from the call

PropertyUtils.getProperty(inventoryStatusForm, "released.numTons"); when a
java.lang.Double and a primitive double is used for numTons.
And if they are different from java.lang.Double, there should be something
which should be confusing PropertyUtils.

Just curious. What version of beanutils and JDK do you use?