Thanks Adam,
Unfortunately, that doesn't work. Are there other implicit objects in
the OGNL value stack that might give a more direect reference to the
action?
Eric.
On Mar 26, 2007, at 5:10 PM, Adam Ruggles wrote:
have you tried <ww:property value="#top.user.username" />
Eric Rank wrote:
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>
<p>
<label>The User from the Action: </label>
<s:property value="%{user.name}" />
</p>
<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">
<p>
<label>Expecting the Action's user, but I get the userBox's
User</label>
<s:property value="%{user.name}" />
</p>
<p>
<label>Try using #this, but I still get the userBox's User</
label>
<s:property value="%{#this.user.name}" />
</p>
<p>
<label>This makes comparing objects in the iterator with the
action difficult.
Doing an 'equals' test should return false:
</label>
<s:property value="%{user.name.equals(userBox.user.name)}" />
</p>
</s:iterator>
---------- 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>();
userBoxes.add(box);
}
//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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]