struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ashwin ala <ashwin...@gmail.com>
Subject Formatting in extended theme using Freemarker
Date Sat, 12 Sep 2009 03:43:55 GMT
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.

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message