Number types with custom formatting

"Smerek, Martin" <[email protected]> Thu, 4 Apr 2013 15:10:21 -0700
Newsgroups gmane.comp.web.freemarker.user
Message-ID <7FFCC49A9CDC1441891365778636475A8B9B6171@corpmail2007.corp.netledger.com>
<html><body>Hi all,

We'd like to use FreeMarker for our project. We have special formatting for different number types (internal id, multiple currencies, quantity) and we'd like to offer our users a comfort of automatic formatting without making them to call build-ins, e.g. use simply

${transaction.total}
${transaction.quantity}

instead of

${transaction.total?string.currency}
${transaction.quantity?string.number}

We tried to implement both TemplateNumberModel and TemplateScalarModel interfaces, but in freemarker.core.Expression.getStringValue(TemplateModel, Expression, Environment), TemplateNumberModel always takes priority before TemplateScalarModel. This results in one global format for all number types.

Quick and dirty solution is to move the above mentioned condition with TemplateScalarModel before the one with TemplateNumberModel. However, we aren't sure why the sequence of the conditions looks as it does and if the change wouldn't cause some other problem. Any thoughts on this?

Is there any way how to treat a number as number (to support comparison and arithmetics) but format it in completely custom way?

Thank you very much,
Martin Smerek


NOTICE: This email and any attachments may contain confidential and proprietary information of NetSuite Inc. and is for the sole use of the intended recipient for the stated purpose. Any improper use or distribution is prohibited. If you are not the intended recipient, please notify the sender; do not review, copy or distribute; and promptly delete or destroy all transmitted information. Please note that all communications and information transmitted through this email system may be monitored by NetSuite or its agents and that all incoming email is automatically scanned by a third party spam and filtering service

</body></html>

------------------------------------------------------------------------------
Minimize network downtime and maximize team effectiveness.
Reduce network management and security costs.Learn how to hire 
the most talented Cisco Certified professionals. Visit the 
Employer Resources Portal
http://www.cisco.com/web/learning/employer_resources/index.html

_______________________________________________
FreeMarker-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/freemarker-user