From what i understand the new Struts2 – the value stack stores the action objects and put those member variables of the action objects onto itself – hence like a virtual object. Supposedly on my html using struts2 tag, i want to display one of the member variable but there are few of them having the same name.
<s:property name="memberpropertyname"/>
The value stack access this name from top to bottom. What if the top one is the incorrect one? How does it resolve it and pick say the last one – which is the one for me.
Any help please ..
If your application actually has a legitimate reason to shade values, you have a few options. In general, however, the top-most stack item (usually the action) should be the thing exposing data to the view layer.
You can directly access whatever is at a specific stack depth via array notation:
This bypasses the top-most item on the stack and examples the next one down explicitly.
This is almost never necessary in a reasonable application. At most you might need to directly access an action property, for example, during an iteration, or if something has been
<s:push>ed onto the stack (also rare). Accessing action properties is simple:I’d suggest if you find that you need to access data lower in the stack than the action, and the action is obscuring the view to those lower layers, that you’re doing it wrong. If nothing else, whatever is putting the object you need onto the stack before the action is pushed should push an object that’s unlikely to be exposed by an action.
For example, a filter that sticks some app-wide data might use a generic name:
Without understand your usecase and how this situation has come to be it’s difficult to provide more specific assistance. My gut reaction is that something has gone wrong, though.