我有以下动作类:
@Namespace("/admin_side")
@ResultPath("/WEB-INF/content")
@ParentPackage(value="struts-default")
public final class FabricAction extends ActionSupport implements Serializable, ValidationAware, Preparable, ModelDriven<Fabric>
{
@Autowired
private final transient FabricService fabricService=null;
private static final long serialVersionUID = 1L;
private int pageSize=5;
private Long id;
private Boolean deleteOneRow;
private Boolean deleteMultipleRows;
private String message;
private List<Long>chk;
private Long deleteId;
private Long begin;
private Long end;
private Long currentPage=1L;
private Long rowCount;
private Long totalPages;
private Integer status;
private Fabric entity=new Fabric();
private List<Fabric>fabrics=new ArrayList<Fabric>();
//Getters & Setters.
@Action(value = "Fabric",
results = {
@Result(name=ActionSupport.SUCCESS, location="Fabric.jsp"),
@Result(name = ActionSupport.INPUT, location = "Fabric.jsp")},
interceptorRefs={
@InterceptorRef(value="paramsPrepareParamsStack", params={"params.acceptParamNames", "id, currentPage, rowCount, totalPages, message, status", "validation.validateAnnotatedMethodOnly", "true", "validation.excludeMethods", "load"})})
public String load() throws Exception
{
//Invokes, when the page is loaded.
return ActionSupport.SUCCESS;
}
@Action(value = "FabricPage",
results = {@Result(name=ActionSupport.SUCCESS, location="Fabric.jsp", params={"namespace", "/admin_side", "actionName", "Fabric", "currentPage", "${currentPage}"}),
@Result(name = ActionSupport.INPUT, location = "Fabric.jsp")},
interceptorRefs={
@InterceptorRef(value="conversionError"),
@InterceptorRef(value="paramsPrepareParamsStack", params={"params.acceptParamNames", "currentPage", "validation.validateAnnotatedMethodOnly", "true"})})
public String page()
{
//Invokes, when a page link is clicked.
return ActionSupport.SUCCESS;
}
@Validations(
requiredStrings={
@RequiredStringValidator(fieldName="fabricName", type= ValidatorType.FIELD, key = "fabric.name.required")},
stringLengthFields={
@StringLengthFieldValidator(fieldName="fabricName", type= ValidatorType.FIELD, minLength="2", maxLength="45", key="fabric.name.length", messageParams={"2", "45"})})
@Action(value = "AddFabric",
results = {
@Result(name=ActionSupport.SUCCESS, type="redirectAction", location="Fabric.jsp", params={"namespace", "/admin_side", "actionName", "Fabric", "currentPage", "${currentPage}", "message", "${message}", "id", "${id}", "status", "${status}"}),
@Result(name = ActionSupport.INPUT, location = "Fabric.jsp")},
interceptorRefs={
@InterceptorRef(value="conversionError"),
@InterceptorRef(value="paramsPrepareParamsStack", params={"params.acceptParamNames", "id, fabricId, fabricName, currentPage, rowCount, totalPages, status", "validation.validateAnnotatedMethodOnly", "true"})
})
public String insert()
{
//Handles insert and update operations.
return ActionSupport.SUCCESS;
}
@Action(value = "EditFabric",
results = {
@Result(name=ActionSupport.SUCCESS, location="Fabric.jsp"),
@Result(name = ActionSupport.INPUT, location = "Fabric.jsp")},
interceptorRefs={
@InterceptorRef(value="paramsPrepareParamsStack", params={"params.acceptParamNames", "id, fabricId, fabricName, currentPage", "validation.validateAnnotatedMethodOnly", "true"}),
@InterceptorRef(value="conversionError")})
public String edit()
{
//Invokes, when an edit link is clicked.
return ActionSupport.SUCCESS;
}
@Validations(
fieldExpressions={@FieldExpressionValidator(fieldName="deleteOneRow", expression="deleteOneRow==true", shortCircuit=true, key="delete.row.reject")})
@Action(value = "DeleteFabric",
results = {
@Result(name=ActionSupport.SUCCESS, type="redirectAction", location="Fabric.action", params={"currentPage", "${currentPage}", "message", "${message}", "status", "${status}"}),
@Result(name = ActionSupport.INPUT, location = "Fabric.jsp")},
interceptorRefs={
@InterceptorRef(value="paramsPrepareParamsStack", params={"params.acceptParamNames", "deleteId, deleteOneRow, currentPage, status", "validation.validateAnnotatedMethodOnly", "true"}),
@InterceptorRef(value="conversionError")})
public String deleteSingleRow()
{
//Handles deletion of a single row.
return ActionSupport.SUCCESS;
}
@Validations(
requiredFields={
@RequiredFieldValidator(type= ValidatorType.FIELD, fieldName="chk", key="delete.multiple.alert"),
@RequiredFieldValidator(type= ValidatorType.FIELD, fieldName="deleteMultipleRows", key="delete.multiple.confirm")})
@Action(value = "DeleteFabrics",
results = {
@Result(name=ActionSupport.SUCCESS, type="redirectAction", location="Fabric.jsp", params={"namespace", "/admin_side", "actionName", "Fabric", "currentPage", "${currentPage}", "message", "${message}", "status", "${status}"}),
@Result(name = ActionSupport.INPUT, location = "Fabric.jsp")},
interceptorRefs={
@InterceptorRef(value="paramsPrepareParamsStack", params={"params.acceptParamNames", "deleteMultipleRows, chk, currentPage, rowCount, totalPages", "validation.validateAnnotatedMethodOnly", "true"}),
@InterceptorRef(value="conversionError")})
public String deleteMultipleRows()
{
//Handles deletion of multiple rows.
return ActionSupport.SUCCESS;
}
public Fabric getEntity() {
return entity;
}
public void setEntity(Fabric entity) {
this.entity = entity;
}
public List<Fabric> getFabrics()
{
return fabrics;
}
@Override
public Fabric getModel()
{
return entity;
}
@Override
public void prepare() throws Exception
{
fabrics= fabricService.getList((int)(currentPage-1)*pageSize, pageSize);
}
}
在执行除了与insert()
方法关联的插入和更新之外的所有操作(它们都与insert()
映射到<s:submit>
动作的关联)时,该prepare()
方法只执行一次。
在执行插入或更新时, prepare()
可以看到该方法被调用了两次。为什么会这样?
type="redirectAction"
在in的情况下@Result()
,该prepare()
方法被执行两次。当of设置为时,有没有办法防止该prepare()
方法被执行两次?type
@Result
redirectAction