Thursday, 14 April 2016

How to do formatting using properties file ?


You can use s:text tag built-in formatting functionality to format your date and numbers.

JSP
<s:text name="product.name">
   <s:param name="value" value="productName"/>
</s:text>

<s:text name="product.cost" >
   <s:param name="value" value="productCost"/>
</s:text>

<s:text name="product.orderDate">
   <s:param name="value" value="orderDate"/>
</s:text>


messageresource properties file
product.cost = USD {0,number,##0.00}
product.orderDate = {0,date,dd-MMM-yyyy}
product.name = {0}
 
You can easily define or change the formatting of output just modifying the properties file.

Output of JSP
name: ICE cream
cost: USD 102.08
date: 10-Jun-2010

No comments:

Post a Comment

Note: only a member of this blog may post a comment.