wood burning stoves*
The moose likes Struts and the fly likes formating report datewise Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Frameworks » Struts
Bookmark "formating report datewise" Watch "formating report datewise" New topic
Author

formating report datewise

aamchi mumbai
Greenhorn

Joined: Mar 04, 2005
Posts: 19
Hi,

i have report data in arraylist

ArrayList al = new ArrayList();
HashMap hm = new HashMap();

hm.add("01/01/2005");
hm.add("one");
hm.add("two");
hm.add("test");

al.add(hm);

hm=new HashMap();
hm.add("01/01/2005");
hm.add("three");
hm.add("four");
hm.add("test");

al.add(hm);

hm=new HasmMap();
hm.add("01/02/2005");
hm.add("five");
hm.add("six");
hm.add("test");

al.add(hm);

now i want to display this report datewise

01/01/2005
one two
three four
01/02/2005
five six


Is there any way that i can use struts tag and display in this format or i have to use scriptlet only. i know how to iterate but i dont how to store date to compare...

Thanks in Advance
alan do
Ranch Hand

Joined: Apr 14, 2005
Posts: 354
using scriptlets or logic:xxx tags to sort is a poor approach. the data SHOULD be sorted in an ordered list in the 'backend' (in an action utility method or something). the logic:iterate or c:forEach then would only need to do what they are meant to do.

personally, i would store your hashmap minus the date into a wrapper object, say Report. this would contain 2 fields, a 'date' of type Date and 'data' of type HashMap. create each Report instance and add it to an ArrayList then use Collections.sort(myArrayList, DateComparator). you'll have to write your DateComparator. oh, and life will be easier if you use JSTL c tag-lib instead of logic.


-/a<br />certified slacker...yes, my last name is 'do' - <a href="http://www.luckycouple.com" target="_blank" rel="nofollow">luckycouple.com</a>
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: formating report datewise