Solved

JSTL Scope problem

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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
countPairs challenge 7 74
countAbc challenge 9 60
Non-recursive backtracking, using a stack 1 137
java 8 lambda expresssions exception handling 3 91
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.

832 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