【新人救助】EL表达式为什么可以在值栈中取值
本帖最后由 iwieijakdf 于 2014-01-07 08:16:12 编辑 我在后台将一个对象的list集合放到了值栈的Map栈中
public String getLastVersionPD(){
ActionContext.getContext().put("pdList", this.pdManager.getLastVersonPD());
return "listAction";
}
<s:iterator value="#pdList">
<s:property value="name"/>
<s:property value="version"/>
<s:a action="pdManagerAction_delete?key=%{key}">删除</s:a>
<a href="javascript: showProcessImage('${requestScope.deploymentId}')">查看流程图</a>
</s:iterator>
public Object getAttribute(String s) {
if (s != null && s.startsWith("javax.servlet")) {
//如果是${requestScope.javax.servlet.属性名的}就直接去request里面取值
return super.getAttribute(s);
}
//关键在下面,先从request里面取值取不到时就从值栈里面取值,所以就可以解释楼主这个为啥也能取到值了
ActionContext ctx = ActionContext.getContext();
Object attribute = super.getAttribute(s);
if (ctx != null) {
if (attribute == null) {
boolean alreadyIn = false;
Boolean b = (Boolean) ctx.get("__requestWrapper.getAttribute");
if (b != null) {
alreadyIn = b.booleanValue();
}
if (!alreadyIn && s.indexOf("#") == -1) {
try {
// If not found, then try the ValueStack
ctx.put("__requestWrapper.getAttribute", Boolean.TRUE);
ValueStack stack = ctx.getValueStack();
if (stack != null) {
attribute = stack.findValue(s);
}
} finally {
ctx.put("__requestWrapper.getAttribute", Boolean.FALSE);
}
}
}
}
return attribute;
}