?
Solved

JSTL forEach Tag

Posted on 2003-03-11
4
Medium Priority
?
2,311 Views
Last Modified: 2013-11-24
I have the following in the JSP. Tag libs are all configured properly. The array list object I want to iterate through is also fine, ie., the sys.out prints out values in the array list. But I get an empty drop-down list. What is wrong? How do I fix it? Please help ASAP.

<% ArrayList projects = DBUtil.getList(DBUtil.PROJECT);
     if(projects == null ) {
          System.out.println("PROJECT IS NULL");
     } else {
          System.out.println("PROJECT IS "+projects);    
     }
%>
<SELECT>
    <c:forEach var="project" items="${projects}">
     <OPTION value=<c:out value="${project}"/>><c:out value="${project}"/></OPTION>
    </c:forEach>
</SELECT>

Thanks,
Padma.
0
Comment
Question by:vpadma
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 35

Expert Comment

by:TimYates
ID: 8114791
Does:

---------------------

<OPTION value='<c:out value="${project}"/>'><c:out value="${project}"/></OPTION>

---------------------

(with single quotes) work any better?

What if you replace it with:

---------------------

<%
  if( projects != null )
  {
%>
Size equals <%= projects.size() %>
<SELECT>
<%
  for( java.util.Iterator i = projects.iterator() ; i.hasNext() ; )
  {
    String str = (String)i.next()
%>
    <OPTION value='<%= str %>'><%= str %></OPTION>
<%
  }
%>
</SELECT>
<%
  }
%>

---------------------

Does it fill then?  Guess so...but it will let you check that you are getting data back :-)
0
 
LVL 28

Accepted Solution

by:
rrz earned 300 total points
ID: 8115254
You have set "projects" as a scripting variable.
try adding a line in the scriptlet.
<% ArrayList projects = DBUtil.getList(DBUtil.PROJECT);
    if(projects == null ) {
         System.out.println("PROJECT IS NULL");

    } else {
         System.out.println("PROJECT IS "+projects);  
         pageContext.setAttribute("mylistarray",projects);
    }
%>
then access in tags ${mylistarray}
0
 
LVL 28

Expert Comment

by:rrz
ID: 8116047
>${projects}
this expression will return value of the page-scoped variable named "projects" if one had existed. But "projects" is your scripting variable.
Please use the JSP topic area for JSTL questions.
0
 
LVL 2

Author Comment

by:vpadma
ID: 8119550
Perfect. Although I found out yeterday and modified it as
<c_rt:set var='projects' value='<%= DBUtil.getList(DBUtil.PROJECT) %>'/>

that was the reason my code was not working earlie,  I appreciate your help.

Padma.
0

Featured Post

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
Suggested Courses
Course of the Month11 days, 16 hours left to enroll

752 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