Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

JSTL Scope problem

Posted on 2006-11-20
3
Medium Priority
?
590 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 900 total points
ID: 17985820
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
ID: 17991771


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
ID: 17993152
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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

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 …
A solution for Fortify Path Manipulation.
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.
Suggested Courses

877 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