You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by ashwin ala <as...@gmail.com> on 2009/09/12 05:43:55 UTC

Formatting in extended theme using Freemarker

We currently display BigDecimal values in <s:textfield> tags in our jsps.
These values need to be formatted to display as currency values. Example:
"123.350000" should display as "123.35"
I extended the simple theme to create a currency theme using only the
text.ftl template file. I basically copied the text.ftl to
/template/currency and changed this line:

<#if parameters.nameValue??>
 value="<@s.property value="parameters.nameValue"/>"<#rt/>
</#if>

to this:
<#if parameters.nameValue??>
 value="<@s.property
value="%{getText('{0,number,#.00}',{parameters.nameValue})}"/>"<#rt/>
</#if>

This does not work and gives a template error like
 (WARNING: Parameters: Invalid chunk ignored.).

The extended theme by itself does work as this line works:
<#if parameters.nameValue??>
 value="<@s.property value="parameters.nameValue*5"/>"<#rt/>
</#if>
...which multiplies the bigdecimal value by 5 before displaying.

So can anyone let us know what is the best way to apply formatting in an
extended theme in a freemarker template? We also have some date values that
need formatting so will create another theme for that. I could add getText()
to each <s:textfield> tag explicitly but specifying a theme that handles the
formatting seems a lot cleaner. I have also tried freemarker formatting like
the one below with no success

${x?string("0.##")}

Any help or pointers would be much appreciated.

thanks
ash.

RE: Formatting in extended theme using Freemarker

Posted by Martin Gainty <mg...@hotmail.com>.
did you try formatting your variable as string.currency?

<#assign x=123.350000>
${x?string.currency}

http://freemarker.sourceforge.net/docs/ref_builtins_number.html

other solutions?
Martin 
______________________________________________ 
Verzicht und Vertraulichkeitanmerkung/Note de déni et de confidentialité
 
Diese Nachricht ist vertraulich. Sollten Sie nicht der vorgesehene Empfaenger sein, so bitten wir hoeflich um eine Mitteilung. Jede unbefugte Weiterleitung oder Fertigung einer Kopie ist unzulaessig. Diese Nachricht dient lediglich dem Austausch von Informationen und entfaltet keine rechtliche Bindungswirkung. Aufgrund der leichten Manipulierbarkeit von E-Mails koennen wir keine Haftung fuer den Inhalt uebernehmen.
Ce message est confidentiel et peut être privilégié. Si vous n'êtes pas le destinataire prévu, nous te demandons avec bonté que pour satisfaire informez l'expéditeur. N'importe quelle diffusion non autorisée ou la copie de ceci est interdite. Ce message sert à l'information seulement et n'aura pas n'importe quel effet légalement obligatoire. Étant donné que les email peuvent facilement être sujets à la manipulation, nous ne pouvons accepter aucune responsabilité pour le contenu fourni.




> Date: Fri, 11 Sep 2009 20:43:55 -0700
> Subject: Formatting in extended theme using Freemarker
> From: ashwinala@gmail.com
> To: user@struts.apache.org
> 
> We currently display BigDecimal values in <s:textfield> tags in our jsps.
> These values need to be formatted to display as currency values. Example:
> "123.350000" should display as "123.35"
> I extended the simple theme to create a currency theme using only the
> text.ftl template file. I basically copied the text.ftl to
> /template/currency and changed this line:
> 
> <#if parameters.nameValue??>
>  value="<@s.property value="parameters.nameValue"/>"<#rt/>
> </#if>
> 
> to this:
> <#if parameters.nameValue??>
>  value="<@s.property
> value="%{getText('{0,number,#.00}',{parameters.nameValue})}"/>"<#rt/>
> </#if>
> 
> This does not work and gives a template error like
>  (WARNING: Parameters: Invalid chunk ignored.).
> 
> The extended theme by itself does work as this line works:
> <#if parameters.nameValue??>
>  value="<@s.property value="parameters.nameValue*5"/>"<#rt/>
> </#if>
> ...which multiplies the bigdecimal value by 5 before displaying.
> 
> So can anyone let us know what is the best way to apply formatting in an
> extended theme in a freemarker template? We also have some date values that
> need formatting so will create another theme for that. I could add getText()
> to each <s:textfield> tag explicitly but specifying a theme that handles the
> formatting seems a lot cleaner. I have also tried freemarker formatting like
> the one below with no success
> 
> ${x?string("0.##")}
> 
> Any help or pointers would be much appreciated.
> 
> thanks
> ash.

_________________________________________________________________
Hotmail: Powerful Free email with security by Microsoft.
http://clk.atdmt.com/GBL/go/171222986/direct/01/

Re: Formatting in extended theme using Freemarker

Posted by Paweł Wielgus <po...@gmail.com>.
Hi,
bigdecimal knows its own rounding,
can't You use it?
Also You can write your own bigdecimal converter,
but it think it won't be necessary in this case.

Best greetings,
Pawel Wielgus.

2009/9/12, ashwin ala <as...@gmail.com>:
> We currently display BigDecimal values in <s:textfield> tags in our jsps.
> These values need to be formatted to display as currency values. Example:
> "123.350000" should display as "123.35"
> I extended the simple theme to create a currency theme using only the
> text.ftl template file. I basically copied the text.ftl to
> /template/currency and changed this line:
>
> <#if parameters.nameValue??>
>  value="<@s.property value="parameters.nameValue"/>"<#rt/>
> </#if>
>
> to this:
> <#if parameters.nameValue??>
>  value="<@s.property
> value="%{getText('{0,number,#.00}',{parameters.nameValue})}"/>"<#rt/>
> </#if>
>
> This does not work and gives a template error like
>  (WARNING: Parameters: Invalid chunk ignored.).
>
> The extended theme by itself does work as this line works:
> <#if parameters.nameValue??>
>  value="<@s.property value="parameters.nameValue*5"/>"<#rt/>
> </#if>
> ...which multiplies the bigdecimal value by 5 before displaying.
>
> So can anyone let us know what is the best way to apply formatting in an
> extended theme in a freemarker template? We also have some date values that
> need formatting so will create another theme for that. I could add getText()
> to each <s:textfield> tag explicitly but specifying a theme that handles the
> formatting seems a lot cleaner. I have also tried freemarker formatting like
> the one below with no success
>
> ${x?string("0.##")}
>
> Any help or pointers would be much appreciated.
>
> thanks
> ash.
>

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