• Post Reply Bookmark Topic Watch Topic
  • New Topic

help with JSTL core forEach tag

 
Scott
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to use the <c:forEach> tag to iterate a list and pull out java beans so I can display the properties to the user. Here is the the first line of code:
<c:forEach var="address" items="${addressList}">

For some reason when I try to access the address object inside the forEach tag I am getting the following error:
cannot resolve symbol symbol : variable address

Can someone please help me figure out what is causing this error? Thanks!!!

My code is below:

<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>
<%@ taglib uri="/WEB-INF/displaytag-12.tld" prefix="display" %>
<%@ taglib uri="/WEB-INF/c.tld" prefix="c" %>

<head>
<link rel="stylesheet" type="text/css" href="screen.css" />
</head>

<html>
<head><title>List of Addresses</title></head>
<body>
<center>

<c:forEach var="address" items="${addressList}">

<%= address.getLastName%> <!-- this is a test to see if the variable can be accessed -->


<display:table pagesize="10" export="true" name="address" width="100%" class="mars">
<display:column property="lastName" title="Last Name"/>
<display:column property="firstName" title="First Name"/>
<display:column property="streetAddress" title="Street Address"/>
<display:column property="townCity" title="City"/>
<display:column property="state"/>
<display:column property="zip"/>
</display:table>

</c:forEach>

</center>
</body>
</html>
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65522
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"hacktorious",

We're pleased to have you here with us in the JSP forum, but there are a few rules that need to be followed, and one is that proper names are required. Please take a look at the JavaRanch Naming Policy and adjust your display name to match it.

In particular, your display name must be a first and a last name separated by a space character, and must not be obviously fictitious.

Thanks!
bear
Forum Bartender
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65522
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<c:forEach var="address" items="${addressList}">

<%= address.getLastName%> <!-- this is a test to see if the variable can be accessed -->


You're mixing apples and oranges. The c:forEach tag will create a scoped variable named address, but your reference is expecting a scriptlet variable. These are incompatible.

The proper way to perform the reference would be:

 
Scott
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This worked. Thanks!!!
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65522
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your welcome.

Btw, "Joe Blow" doesn't cut the mustard either as it fails the 'obviously fictitious' check. Please adjust accordingly.
 
Scott
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Unfortunately that's my real name.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!