Win a copy of TDD for a Shopping Website LiveProject this week in the Testing forum!
  • 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
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

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.
 
Let me tell you a story about a man named Jed. He made this tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic