struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Eric Rank <>
Subject Iterator item and Action getter methods collide [S2]
Date Mon, 26 Mar 2007 16:34:09 GMT
Hi Everyone,

I'm having an interesting experience with the use of the iterator tag  
(Struts 2.0.6).

I have an action with getter method signature which is the same as  
the getter of an iterator item.

As such when I'm within an iterator loop, and I call the getter of  
the Action value, I actually get the value of the current item of the  
iterator loop. To my surprise, the iterator tag adds the current  
iterator item to the value stack, such that when I do <s:property  
value="%{#this}" /> I see the Action as well as the iterator item.

When working within an iterator block, how can I get the value of the  
Action's getter, instead of the iterator item's value?

Concept code below

<h1>Outside if the iterator, I get what I expect</h1>
   <label>The User from the Action: </label>
   <s:property value="%{}" />

<h1>Inside the iterator tag, invoking the property tag in the same  
way, I get the iterator's item</h1>
<s:iterator value="%{userBoxes}" id="userBox">
     <label>Expecting the Action's user, but I get the userBox's  
     <s:property value="%{}" />
     <label>Try using #this, but I still get the userBox's User</label>
     <s:property value="%{}" />

      <label>This makes comparing objects in the iterator with the  
action difficult.
                    Doing an 'equals' test should return false:
     <s:property value="%{}" />

---------- Java below ---------------------------

class MyAction extends ActionSupport{

   private User user = null;
   private List<UserBox> userBoxes = null;

   //Creates a user for the action's 'user' member
   //as well as a List of items with objects containing
   //a method that's the same as the Action's
   public String execute() throws Exception{
     user = new User("Action's User");

     User boxedUser = new User("Boxed User");
     UserBox box = new UserBox(boxedUser)
     userBoxes = new ArrayList<UserBox>();

   //Getter and setter for userBoxes
   public List<UserBox> getUserBoxes(){return userBoxes;}
   public void setUserBoxes(List<UserBox> boxes){userBoxes = boxes;}

   //Getter and setter for the Action's User
   public User getUser(){return user;}
   public void setUser(User u){user = u;}

//Immutable User
class User{
   private String name = null;
   public User(String n){
     name = n;
   public String getName(){return name;}

//Class containing a User member
class UserBox{
   private User user = null;
   public UserBox(User u){
     user = u;

   //This has the same getter signature as the Action
   public User getUser(){
     return user;

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message