Solved

JSTL Scope problem

Posted on 2006-11-20
3
586 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 300 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

Why You Need a DevOps Toolchain

IT needs to deliver services with more agility and velocity. IT must roll out application features and innovations faster to keep up with customer demands, which is where a DevOps toolchain steps in. View the infographic to see why you need a DevOps toolchain.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
allswap challenge 6 152
HashMap Vs TreeMap 12 75
servlet web applications   metadata-complete="true" or false 3 308
hibernate example issues from command prompt 10 85
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 …
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.

738 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