0

I have map which has List as values and Integers as keys.I want to display the values of the list if the key is 0,1 .How is it possible using Struts2 in jsp?

Map<Integer, List<String>> parameter_map = new LinkedHashMap<Integer, List<String>>();
<s:iterator value="parameter_map">
  <h3><s:property value="key" /></h3>
  <table>
    <s:iterator value="value">
      <tr><td><s:property /></td></tr>
    </s:iterator>
  </table>
</s:iterator>

This is what I tried to do in jsp to display.But nothing is displayed.

Dave Newton
  • 158,873
  • 26
  • 254
  • 302
Soham
  • 91
  • 2
  • 6
  • 15
  • which map? please provide relevant code section – Umesh Awasthi Aug 29 '12 at 17:25
  • edit option does not edit code properly. – Soham Aug 29 '12 at 17:28
  • Thanks ..I am trying to display the list in the jsp.I know how to display values in hash map.No idea of how to display the list values? – Soham Aug 29 '12 at 17:33
  • possible duplicate of [Iterate over an HashMap> with Struts 2](http://stackoverflow.com/questions/6237223/iterate-over-an-hashmapstring-arrayliststring-with-struts-2) – BalusC Aug 29 '12 at 17:36
  • Do you have a public getter `getParameter_map` (I think that would be the right name, I *really* wish you'd use normal Java naming parameters to completely avoid an entire class of potential issues)? Have you verified there's actually data in the map? Right now it just looks empty. – Dave Newton Aug 29 '12 at 18:42
  • @DaveNewton yes I have getter for the same. – Soham Aug 29 '12 at 18:44
  • @Soham Works fine for me w/o modification. Check your assumptions. – Dave Newton Aug 29 '12 at 18:48
  • Assumptions? Could you explain? Thank you.I am getting a empty list box. – Soham Aug 29 '12 at 18:52
  • Assumptions about data, application flow, etc. The syntax is correct, therefore there is either no data, you're not hitting the JSP you think you are, etc. – Dave Newton Aug 29 '12 at 18:58

1 Answers1

0

Have you tried using the iterator tag.It can do the work for you and will push the List on the top of value stack which you can again iterate over, so in short you need a set of nested iterator.

There are couple of examples out there which can show you how to iterate over the map.

Have a look at following links

Community
  • 1
  • 1
Umesh Awasthi
  • 23,407
  • 37
  • 132
  • 204
  • @Soham Define "does not work." You don't describe the code you're trying, so it's impossible to diagnose. You don't say what goes wrong, so all we can do is guess. – Dave Newton Aug 29 '12 at 18:22
  • @Dave I have edited the question.Please take a look at it and let me know whats going wrong. – Soham Aug 29 '12 at 18:41
  • @Soham: what you have describe din your code should work and i believe as suggested in comments you need to check if there is data coming in list or not – Umesh Awasthi Aug 30 '12 at 01:48