Struts 2 - Accessing different properties on the ValueStack sharing the same name

泄露秘密 提交于 2019-12-11 00:35:34

问题


Struts 2 will resolve all property names during view rendering against the top object in the ValueStack first. But how can one access a property with the same name on the object lower on the stack?

Example:

Let's say I have an Action class called MyAction and it has a a logDate property. In the view rendered after this action is invoked, there's this:

<s:iterator value="users" status="itStatus">
  <s:property value="logDate"/>
</s:iterator>

Now imagine a User object also has a logDate property. During the iteration, Struts 2 will always push the current user object to the top of the ValueStack effectively resolving all property names against it. But, what if I wanted to access logDate from the action? What's the correct way to do this?


回答1:


You can use an index to look at a substack. For example: [0].logDate would start the search at the stop of the stack and find the logDate on the user object. [1].logDate would start the search one level deeper and find the logDate on the Action class. This OGNL page (see the section right above the Accessing static properties header) has some more detail and here is another explanation.



来源:https://stackoverflow.com/questions/2939005/struts-2-accessing-different-properties-on-the-valuestack-sharing-the-same-nam

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!