This week's book giveaways are in the Cloud and AI/ML forums.
We're giving away four copies each of Cloud Native Patterns and Natural Language Processing and have the authors on-line!
See this thread and this one for details.
Win a copy of Cloud Native PatternsE this week in the Cloud forum
or Natural Language Processing in the AI/ML 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Knute Snortum
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Piet Souris
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

How to display data from two different collection using <logic:iterate> tag

 
Greenhorn
Posts: 9
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I have two collection objects, say for example two HashMap instance employeName with empId as key and Empoyee name as value and employeeSalary contains empId as key and Salary as Value. The data in these two maps are related and need to be displayed in table. I need to display data from these two collections in page using single logic:iterate tag. I will be fetching empoyee name from employeeName and related salary value from second map employeeSalary using the empId key from first one.


Does struts supports this kind of requirement or I have to look for something else. What are the other option to display If I can not do it with single <logic:iterate> tag.

Thanks in advance.
 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just a suggestion, instead of using two HashMaps on JSP page why not just use one List of Users objects in your class and access it in JSP page:


 
J john
Greenhorn
Posts: 9
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi James,

Thanks for the response. I thought of implementing it as you suggested. But this will not resolve the problem

Here is code fragment that I am using.

From action class i am setting this two attributes
httpServletRequest.setAttribute("recordsIterator", records.values().iterator() ); // records is a HashMap instance
httpServletRequest.setAttribute("stationStatusMap", stationStatus); // stationStatus is another instance of HashMap


This is the JSP file. I am reading values from the iterator passed from the action class.
<logic:iterate name="recordsIterator" id="priceChangeRec" >
<tr>
<td><bean:write name="priceChangeRec" property="stationName"/></td>
<td><bean:write name="priceChangeRec" property="changeDirection"/></td>
<td>
<input type="text" size="5" value="<bean:write name="priceChangeRec" property="priceProduct1"/>" />
</td>
<td>
<input type="text" size="5" value="<bean:write name="priceChangeRec" property="priceProduct2"/>" />
</td>
<td>
<input type="text" size="5" value="<bean:write name="priceChangeRec" property="priceProduct3"/>" />
</td>
<td>
<input type="text" size="5" value="<bean:write name="priceChangeRec" property="priceProduct4"/>" />
</td>
<td>
<input type="text" size="5" value="<bean:write name="priceChangeRec" property="priceProduct5"/>" />
</td>
</tr>
</logic:iterate>

As you can see each row in the table displays price of some products of a particular station. The second hashmap contains a status value of each station which is mapped against station name.
I need use the station name from the first iterator and read the status value from second map using that value. I have to display that station status along with price detail in each row for each station.

Hope I made the issue clear to you..

Thanks
John
 
Jaames Smith
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not sure if this is correct way of doing but it will give you idea how to access second HashMap:

 
J john
Greenhorn
Posts: 9
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, It can be done this way. But I am looking for a solution from the struts framework. Thanks James
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!