DIY步骤处理
package test.action;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import org.thj.bookstore.model.InfoModel;
import com.opensymphony.xwork.ActionContext;
import com.opensymphony.xwork.ActionSupport;
public class TestAction extends ActionSupport{
private static final long serialVersionUID = 1L;
private String hello;
private int stepNum;
private InfoModel infoModel = new InfoModel();
private Map<Integer,InfoModel> stepMap = new HashMap<Integer,InfoModel>();
public InfoModel getInfoModel() {
return infoModel;
}
public void setInfoModel(InfoModel infoModel) {
this.infoModel = infoModel;
}
public int getStepNum() {
return stepNum;
}
public void setStepNum(int stepNum) {
this.stepNum = stepNum;
}
public String getHello() {
return hello;
}
public void setHello(String hello) {
this.hello = hello;
}
public int getTotalStep(){
if(ActionContext.getContext().getSession().get("stepNum")!=null){
return (Integer)ActionContext.getContext().getSession().get("stepNum");
}else{
return 0;
}
}
public String execute() throws Exception{
this.setHello("hello webwork!!");
return SUCCESS;
}
public String second() throws Exception{
Map session = ActionContext.getContext().getSession();
if(stepNum>0){
session.put("stepNum", stepNum);
}
stepNum = 1;
return SUCCESS;
}
public String next() throws Exception{
Map session = ActionContext.getContext().getSession();
//int totalStep = Integer.parseInt((String)session.get("stepNum"));
if(stepNum<=this.getTotalStep()){
if(stepNum==1){
stepMap.put(stepNum, infoModel);
session.put("part", stepMap);
}else{
stepMap = (Map)session.get("part");
if(!stepMap.containsKey(stepNum)){
System.out.println("next stepNum:"+stepNum);
stepMap.put(stepNum, infoModel);
session.put("part", stepMap);
}
}
if(stepNum==this.getTotalStep()){
stepMap = (Map)session.get("part");
for(Iterator it = stepMap.values().iterator();it.hasNext();){
infoModel = (InfoModel)it.next();
System.out.println("step:"+infoModel.getStep()+"\t");
System.out.println("name:"+infoModel.getName()+"\n");
}
session.remove("stepNum");
session.remove("part");
return NONE;
}
stepNum++;
}
return SUCCESS;
}
}
配置
<action name="hello" class="test.action.TestAction">
<result name="success">/hello.jsp</result>
</action>
<action name="second" class="test.action.TestAction" method="second">
<result name="success">/next.jsp</result>
</action>
<action name="next" class="test.action.TestAction" method="next">
<result name="success">/next.jsp</result>
</action>
hello.jsp
<%@ page contentType="text/html; charset=gb2312" %>
<%@ taglib prefix="ww" uri="/webwork"%>
<html>
<body>
<form action="second.action" method="post">
step:<input name="stepNum"/>
<input type="submit" value="提交"/>
</form>
<ww:property value="hello"/>
</body>
</html>
next.jsp
<%@ page contentType="text/html; charset=gb2312" %>
<%@ taglib prefix="ww" uri="/webwork"%>
<html>
<body>
<form action="next.action" method="post">
step:<input type="hidden" name="stepNum" value="<ww:property value="stepNum"/>"/>
<input name="infoModel.step" value="<ww:property value="stepNum"/>" readonly/>
<input name="infoModel.name" />
<input type="submit" value="提交"/>
</form>
</body>
</html>
lunzi
2008-01-09 00:26:12
评论:0
阅读:83
引用:0
