Help coderanch get a
new server
by contributing to the fundraiser
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

formating report datewise

 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 354
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic