This week's book giveaway is in the Agile and other Processes forum. We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line! See this thread for details.
I have been unsuccessful in utilizing the format attribute with bean:write. I am looking for some insight on what I am doing wrong. The code clip below displays the items in the ArrayList in the same format that they were stored. I don�t get an error with the code below, but the format attribute does nothing. I am using Struts 1.1
Better u go for formatKey attribute of this bean write tag .there in format key u need to give a name which will look up in to resource bundle and display in that format .this is best used for date representation
u make an entry as above in the reosurce bundle and in ur jsp give the key name for formatKey then it will work .......
David Hibbs
Ranch Hand
Joined: Dec 19, 2002
Posts: 374
posted
0
The problem is less with your tag than with your format. I'm guessing by your variable names that you're trying to format an index of less than 1,000 to increments of 1,000 -- i.e. 1 to 1,000 2 to 2,000 etc? Likely you need to change it to something like format="{0}000.00"
"Write beautiful code; then profile that beautiful code and make little bits of it uglier but faster." --The JavaPerformanceTuning.com team, Newsletter 039.
Jay Haley
Greenhorn
Joined: May 18, 2004
Posts: 9
posted
0
I'm still having the same problem. Here's what I tried..am I missing someting? After changing application.properties I did restart my server.
I've just tried your formatting code in a regular java application. The problems seems to be this: You are trying to format numbers represented as String objects. DecimalFormat does not allow for this input, it requires Number objects.
This means: DecimalFormat formatter = new DecimalFormat("#,000.00"); System.out.println(formatter.format(new Double("55555"))); will work, and what you are doing is equivalent to: DecimalFormat formatter = new DecimalFormat("#,000.00"); System.out.println(formatter.format("55555")); which throws an Exception.
You should then try to fill your ArrayList with Double objects, instead of String objects.
Let me know if this helped you out.
SCJP, SCWCD, SCEA
David Hibbs
Ranch Hand
Joined: Dec 19, 2002
Posts: 374
posted
0
Originally posted by Jose Zaleta: Jay,
I've just tried your formatting code in a regular java application. The problems seems to be this: You are trying to format numbers represented as String objects. DecimalFormat does not allow for this input, it requires Number objects.
Jose is on the right track; seeing your output made me suspect something even more, though--that if your object is an instance of String, it would not format it. Rummaging in the source for the bean write tag, I find the following snippet in the code where the format string is applied:
There you have it. You can't alter the format of a String object using the bean:write format options. Of course, you COULD sumbit a patch/Feature request...
Shed Hollaway
Greenhorn
Joined: Aug 11, 2003
Posts: 9
posted
0
Jay,
The format function in bean:write I believe is deprecated. Here's a option using JSTLs
<%@ page language="java"%> <%@ taglib uri="/WEB-INF/c-rt.tld" prefix="c" %> <%@ taglib uri="/WEB-INF/fmt-rt.tld" prefix="fmt-rt" %> <html> <head> <title>JSP for myformatNoForm form</title> </head> <body> <% { java.util.ArrayList list = new java.util.ArrayList(); list.add("55555"); list.add("44444.4"); list.add("23342.354"); pageContext.setAttribute("list", list, PageContext.PAGE_SCOPE); } %> <b>This will do it.</b><br> <c:forEach var="i" items="${list}" ><fmt-rt:formatNumber value="${i}" type="currency" /><br></c:forEach> </body> </html>
That was a good mind twister, I celebrate now
Jay Haley
Greenhorn
Joined: May 18, 2004
Posts: 9
posted
0
Thanks for getting back. I've got several good things to try out after I address a production issue.