Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

formating report datewise

 
aamchi mumbai
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 354
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic