You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Michael Mok <mi...@consultech.net.au> on 2000/09/11 05:10:35 UTC
Format decimal and date fields
Hi
Is it possible to use STRUTS to format the display of decimal and date
fields? If so how can I get about doing it.
I have a Order bean which a contain a date field (eg orderdate of type
Calendar) and a decimal field (eg orderamount BigDecimal)
I managed to create an arraylist of orders (Order bean) and use the iterate
tag to loop through to show each order details however, how do I use it to
format the date and decimal field?
TIA
Eg
<jsp:useBean id="orderlist" scope="session" type="java.util.ArrayList"/>
<table>
<!-- process the result set -->
<struts:iterate id="orderlist" name="orderlist">
<tr>
<td>
<struts:htmlProperty name="orderlist" property="orderDescription"/>
</td>
<td>
<struts:htmlProperty name="orderlist" property="orderDate"/>
</td>
<td>
<struts:htmlProperty name="orderlist" property="orderAmount"/>
</td>
</tr>
</struts:iterate>
</table>
Re: Format decimal and date fields
Posted by "Craig R. McClanahan" <Cr...@eng.sun.com>.
Michael Mok wrote:
> Hi
>
> Is it possible to use STRUTS to format the display of decimal and date
> fields? If so how can I get about doing it.
>
> I have a Order bean which a contain a date field (eg orderdate of type
> Calendar) and a decimal field (eg orderamount BigDecimal)
>
> I managed to create an arraylist of orders (Order bean) and use the iterate
> tag to loop through to show each order details however, how do I use it to
> format the date and decimal field?
>
> TIA
>
> Eg
>
> <jsp:useBean id="orderlist" scope="session" type="java.util.ArrayList"/>
>
> <table>
> <!-- process the result set -->
> <struts:iterate id="orderlist" name="orderlist">
> <tr>
> <td>
> <struts:htmlProperty name="orderlist" property="orderDescription"/>
> </td>
> <td>
> <struts:htmlProperty name="orderlist" property="orderDate"/>
> </td>
> <td>
> <struts:htmlProperty name="orderlist" property="orderAmount"/>
> </td>
> </tr>
> </struts:iterate>
> </table>
Current versions of the Struts form tags do not do any "smart" conversions like this
for you. However, upcoming enhancements will let you use a JavaBeans-style
PropertyEditor class to define conversions to and from a text string format for your
bean properties. Using this, you'd be able to specify the sorts of Locale-sensitive
conversions that you describe here.
Craig
====================
See you at ApacheCon Europe <http://www.apachecon.com>!
Session VS01 (23-Oct 13h00-17h00): Sun Technical Briefing
Session T06 (24-Oct 14h00-15h00): Migrating Apache JServ
Applications to Tomcat