Struts 2-访问共享相同名称的ValueStack上的不同属性 [英] Struts 2 - Accessing different properties on the ValueStack sharing the same name

查看:131
本文介绍了Struts 2-访问共享相同名称的ValueStack上的不同属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Struts 2将首先在视图渲染期间针对ValueStack中的顶部对象解析所有属性名称.但是,如何在堆栈较低的对象上访问具有相同名称的属性?

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?

示例:

比方说,我有一个名为MyAction的Action类,它具有一个logDate属性.在调用此操作后呈现的视图中,有以下内容:

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>

现在想象一个User对象也有一个logDate属性.在迭代过程中,Struts 2始终会将当前用户对象推到ValueStack的顶部,从而有效地解决所有属性名称.但是,如果我想从操作访问logDate怎么办?正确的方法是什么?

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?

推荐答案

您可以使用索引查看子堆栈.例如: [0] .logDate将在堆栈的末尾开始搜索,并在用户对象上找到logDate. [1] .logDate将开始更深一层的搜索,并在Action类上找到logDate. OGNL页面(请参见访问静态内容"正上方的部分属性标题)有更多详细信息,这是另一个解释.

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.

这篇关于Struts 2-访问共享相同名称的ValueStack上的不同属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆