Solved

JSTL Scope problem

Posted on 2006-11-20
3
582 Views
Last Modified: 2013-11-24

I have 3 Beans:  A, B, and C

// Assume getters and setters exist for all element.
// Class A wraps B and C.
public class ABean{
  private B b;

  // ArrayList of C's
  private ArrayList cList;
}

class BBean{
  private String name;
  private String id;
}

class CBean{
   private String name;
   private String id;
   private String color;
}

////  Now we have some JSTL Code

<nested:iterate iproperty="cList" >
    Color = <nested:write property="color" />
   
   Now I want to write the value of another bean in this iterate loop.
     How do I write?  the value of BBean.id here?
</nested:iterate>


How do I get the value of a seperate bean inside an iterate loop.
0
Comment
Question by:tmonteit
  • 2
3 Comments
 
LVL 29

Accepted Solution

by:
bloodredsun earned 300 total points
Comment Utility
This isn't JSTL, it's the Struts nested tags.

If you want to use JSTL you should something like do this (get the ABean class from the scope that it's stored in, e.g. the request and then access the property cList via the getter and then output the color of each item in the list)

<c:forEach var='bean' items='${requestScope.myABean.cList}'>
    Color: <c:out value='${bean.color}'/>
</c:forEach>
0
 

Author Comment

by:tmonteit
Comment Utility


So, using Struts nested tags, how do I write the contents of an element from the parent array being iterated?
0
 

Author Comment

by:tmonteit
Comment Utility
I found a solution that makes this work.  I didn't know you could walk nested properties like a directory.

<nested:iterate property="cList" >
  <nested:write property="../../b.id" />
</nested:iterate>

points awarded for explaining JSTL example.
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

I had a project requirement for a displaying a user workbench .This workbench would consist multiple data grids .In each grid the user will be able to see a large number of data. These data grids should allow the user to 1. Sort 2. Export the …
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
The viewer will learn how to implement Singleton Design Pattern in Java.
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

763 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

7 Experts available now in Live!

Get 1:1 Help Now