Solved

How to loop through list in jsp using for each and retrieve its properties

Posted on 2014-01-25
2
903 Views
Last Modified: 2014-02-04
Hi, I am having trouble understanding how to retrieve properties out of a collection for display in my jsp page.

I am retrieving a list that is Iterable<company> then putting it into a list in my backing bean

here is the code that is in my backing bean to establish the company name

List<Company> companyFullName = Lists.newArrayList();
Iterable<Company>  owner = Lists.newArrayList();

owner = this.groups.owners().activeAsOf(new YearMonth(this.getMonth())).list();

		for(Company company: owner){
			companyFullName.add(company);
			
		}
		
		super.getContext().putIntoRequest("companyFullName",companyFullName);

Open in new window


Here is the JSP snippet

<c:forEach items="${requestScope.companyFullName}" var="currentCompany" varStatus="loop">
<div class="companyAccordion">
<h3>
	${currentCompany.codeName} - ${currentCompany.commonName}
</h3>

						<div>
							<div class="panelContent"></div>
						</div>
					</div>
				</c:forEach>

Open in new window



This of course isn't working, but I'm not sure what exactly I need to do to get these properties out of the list to use in the header.

Could someone please shed some light on this? Thanks!
0
Comment
Question by:grnmachine
2 Comments
 
LVL 6

Accepted Solution

by:
Mahesh Bhutkar earned 500 total points
Comment Utility
Check out this one,

<c:forEach items="${requestScope.companyFullName}" var="currentCompany">
<div class="companyAccordion">
	<h3>
		<c:out value="${currentCompany.codeName}"/> - <c:out value="${currentCompany.commonName}"/>
	</h3>
	<div>
		<div class="panelContent"></div>
	</div>
</div>
</c:forEach>

Open in new window

0
 

Author Comment

by:grnmachine
Comment Utility
Thank you for your response, thats what I was looking for.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now