Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

JSTL Scope problem

Posted on 2006-11-20
3
Medium Priority
?
589 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
[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
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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 …
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
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.

660 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