class SampleAction extends ActionSupport {
private Map<String,String> circleIdNameMap;
public String preprocess(){
--logic for populating value of MAP
}
--getters and setters
}
现在我的问题是我调用的页面加载preprocess
函数并填充值Map
。页面提交后,另一个方法被调用,在此期间,经过一些数据库交互后,它重定向到 JSP,但这一次的值Map
是空的。我正在用这个Map
用于Struts2中的下拉标签。
My preprocess
在链接中关联如下:
href="/gma/preprocessConfigureTspThreshold?operatorId=5102&sessionId=12332"`
所以只有第一次点击链接时preprocess
被调用,之后当我重定向到我的 JSP 时,它不会被调用,所以第二次的值Map
是空的。
我应该将地图放入会话中以便保留它吗?或者可以做点别的吗?
-
我读到不使用preprocess
功能、用途Preparable
界面。但根据文档:
准备方法将始终由 Struts 2 框架的准备拦截器调用
每当为 Action 类调用任何方法时。
因此,每个方法都会调用它。我想preprocess
仅在页面加载时调用。
The prepare
的方法Preparable http://struts.apache.org/maven/xwork-core/apidocs/com/opensymphony/xwork2/Preparable.html每次执行操作时都会调用操作类,这是正确的。这可能就是您为下拉列表准备地图的原因preprocess
方法。
public class SampleAction extends ActionSupport {
private Map<String,String> circleIdNameMap;
private String circleId;
//getters and setters here
protected boolean reload = false;
private void preprocess(){
// Get the Map by calling a stateless Session bean
circleIdNameMap = remoteInterface.getMap();
}
public String action1(){
preprocess();
Map session = ActionContext.getContext().getSession();
session.put("circleIdNameMap ", circleIdNameMap );
return SUCCESS;
}
public String action2(){
Map session = ActionContext.getContext().getSession();
circleIdNameMap = (Map<String,String>)session.get("circleIdNameMap");
if (circleIdNameMap == null){
if (reload) {
preprocess();
Map session = ActionContext.getContext().getSession();
session.put("circleIdNameMap ", circleIdNameMap );
} else {
addActionError("circleIdNameMap is null");
return ERROR;
}
}
return SUCCESS;
}
...//other actions
}
用于下拉的 JSP
<s:select name="circleId" list="circleIdNameMap" listKey="key" listValue="value"/>
这段代码的含义是:你不应该返回结果SUCCESS
or INPUT
如果 JSP 中的字段未初始化。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)