Since the only place a class is cast is where you're casting that thing to a
Double, then that'd have to be it. I'd just assume that what you're getting
is not really a double.
Also, I'd really suggest using JSTL tags (if you're using JSP 2.3) or EL
directly (if you're using 2.4) to manage this. Decorators are fine for
complex conversions, but this isn't that complex. Instead, just do the
display directly in the column content. In fact, there's a tag in the
format library for just this:
<display:column property="amount">
<fmt:formatNumber value="${item.amount}" type="currency"/>
</display:column>
How the "currency" type is interpreted depends on the locale setting, I
think, but I haven't used that particular tag at all.
That should do away with your decorator AND your class cast issue.
Rick Herrick
[EMAIL PROTECTED]
> -----Original Message-----
> From: [EMAIL PROTECTED] [mailto:displaytag-
> [EMAIL PROTECTED] On Behalf Of Oemer Guersoy
> Sent: Thursday, June 29, 2006 8:49 AM
> To: [email protected]
> Subject: [displaytag-user] Unexpected datatype in ColumnDecorator
>
> Hi,
> I wrote a DisplaytagColumnDecorator implementation where the datatype of
> the column value is a String instead of the corresponding properties
> datatype. So I get a ClassCastException.
>
> Any idea what I do wrong?
>
> Here is my code:
>
> -------- The Decorator ---------
>
> package org.displaytag.decorator;
>
> import java.text.DecimalFormat;
> import java.util.Locale;
>
> import javax.servlet.jsp.PageContext;
>
> import org.displaytag.decorator.DisplaytagColumnDecorator;
> import org.displaytag.exception.DecoratorException;
> import org.displaytag.properties.MediaTypeEnum;
>
> public class DisplaytagMoneyWrapper implements DisplaytagColumnDecorator {
>
> private static String moneyToString(double wert) {
> DecimalFormat decimalFormat = (DecimalFormat)
> DecimalFormat.getInstance(Locale.GERMAN);
> decimalFormat.applyPattern("#,###,##0.00");
> String string = decimalFormat.format(round(wert));
> return string;
> }
>
> private static double round(double wert) {
> long longWert = Math.round(wert * 100);
> double doubleWert = longWert;
> doubleWert = doubleWert / 100;
> return doubleWert;
> }
>
> public Object decorate(Object columnValue, PageContext pageContext,
> MediaTypeEnum media) throws DecoratorException {
> return columnValue != null ? moneyToString((Double) columnValue) :
> moneyToString(0);
> }
> }
>
> ----------------------------------
>
> -------- The Table ---------------
>
> <div id="rechnungsausgaengeUebersicht" class="table">
> <display:table name="${form.rechnungsausgaengeUebersicht}" id="row"
> requestURIcontext="false"
> requestURI="${pageContext.request.requestURI}"
> export="true" pagesize="20" sort="list">
> <display:setProperty name="export.pdf.filename"
> value="rechnungsausgaenge-uebersicht.pdf" />
> <display:setProperty name="export.csv" value="true"/>
> <display:setProperty name="export.pdf" value="false"/>
> <display:setProperty name="export.excel" value="true"/>
> <display:setProperty name="export.xml" value="true"/>
>
> ... other columns ...
>
> <display:column media="excel xml csv"
> titleKey="rechnungsausgaenge.uebersicht.honorar"
> autolink="true" paramId="honorar"
> decorator="org.displaytag.decorator.DisplaytagMoneyWrapper">
> ${row.honorar}
> </display:column>
> <display:column media="html"
> headerClass="honorar" paramId="honorar"
> sortProperty="honorar" sortable="true"
> titleKey="rechnungsausgaenge.uebersicht.honorar"
> decorator="org.displaytag.decorator.DisplaytagMoneyWrapper">
> <div class="honorar">${row.honorar}</div>
> </display:column>
>
> ... other columns ...
>
> </display:table>
> </div>
>
> ----------------------------------
>
> Thanks in advance.
>
> Oemer
> --
>
>
> "Feel free" - 10 GB Mailbox, 100 FreeSMS/Monat ...
> Jetzt GMX TopMail testen: http://www.gmx.net/de/go/topmail
>
> Using Tomcat but need to do more? Need to support web services, security?
> Get stuff done quickly with pre-integrated technology to make your job
> easier
> Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
> http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
> _______________________________________________
> displaytag-user mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/displaytag-user
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
displaytag-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/displaytag-user