wood burning stoves 2.0*
The moose likes Struts and the fly likes struts bean:write tag with format key Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "struts bean:write tag with format key" Watch "struts bean:write tag with format key" New topic
Author

struts bean:write tag with format key

Raj Moti
Greenhorn

Joined: Nov 14, 2004
Posts: 4
Hello,

Is it possible to specify something like this
<bean:write name="entity" property="kokiStart" format='MM/dd/yyyy' />
where "kokiStart" is string from "entity" bean.
I want to get output like 12/31/2005
If this is not possible then is there any way by which I can convert any string to the format I want say date or currency.
I am using struts 1.1

Regards
Raj
michelle Wang
Ranch Hand

Joined: Jan 12, 2004
Posts: 65
For the format of Date, I have same pbm as you, I can't find any way to solve it using struts's function. So I write my own DateUtil class to convert string to date, date to String these functions, so can used by the whole project.

And for the currency format, you can check with java API, I use this in JSP, note that the currency will change with your computer currency setting:

<%
NumberFormat currency = NumberFormat.getCurrencyInstance();
double totalAmount= invoiceObj.getTotalAmount();
%>
....
..
<td>Total:</td>
<td>USD</td>
<td><%=currency.format(totalAmount)%>
</td>
[ November 21, 2005: Message edited by: michelle Wang ]

michelle Wang <br />SCJP 1.4
Raj Moti
Greenhorn

Joined: Nov 14, 2004
Posts: 4
Thanks wang.
I will try to overload the bean:write tag with attribute something like charformat or stringformat.
What say ???
michelle Wang
Ranch Hand

Joined: Jan 12, 2004
Posts: 65
For me, I use String to display Date on JSP, bcs String is more easy for you to set the display format.
Srinivas Rao
Greenhorn

Joined: Aug 05, 2004
Posts: 14
Raj,

Over loading the default behaviour with another attribute is best choice and we are doing the same.
 
 
subject: struts bean:write tag with format key
 
Similar Threads
Error with error:bean formatKey parameter
pass results of a struts logic tag to a java method?
Format String in Struts
Date formats
converting strings to dates