struts删除没有调用的动作setter

时间:2017-12-21 22:18:05

标签: java jsp struts2

我有一个像这样的struts动作类:

public class OrderDetailAction extends BaseActionSupport {

   private String ID = new OID().toString();
   private Collection<OrderDetail> orderdetailList;
   private String orderStatus;
   private String shippingAddressId;
   private java.util.Date createdDate;
   private java.util.Date updatedDate;
   private String billingAddressId;

   public void setOrderStatus(String orderStatus) {
        this.orderStatus = orderStatus;
   }

   public String getOrderStatus() {
       return orderStatus;
   }

   public void setShippingAddressId(String shippingAddressId) {
      this.shippingAddressId = shippingAddressId;
   }

   public String getShippingAddressId() {
        return shippingAddressId;
   }
   public void setCreatedDate(java.util.Date createdDate) {
       this.createdDate = createdDate;
   }

   public java.util.Date getCreatedDate() {
       return createdDate;
   }
   public void setUpdatedDate(java.util.Date updatedDate) {
       this.updatedDate = updatedDate;
   }

   public java.util.Date getUpdatedDate() {
       return updatedDate;
   }
   public void setBillingAddressId(String billingAddressId) {
       this.billingAddressId = billingAddressId;
   }

   public String getBillingAddressId() {
       return billingAddressId;
   }
   public String getID() {
       return ID;
   }   

   public void setID(String ID) {
        this.ID = ID;
   }

   public Collection<OrderDetail> getOrderDetailList() {
       return orderdetailList;
   }

   public void setOrderDetailList(Collection<OrderDetail> orderdetailList) {
       this.orderdetailList = orderdetailList;
   }

   // some more logic
}

每当我运行创建操作,显示操作或编辑操作时,struts都会调用所有setter。但是,当我运行删除操作时,struts无法调用除setID()之外的所有setter。

这是否有原因发生?

这是我的struts.xml供参考:

<struts>
       // some other stuff here

        <action name="getOrderDetails" class="presentation.OrderDetailAction" method="getOrderDetails">
            <result name="success">OrderDetailList.jsp</result>
        </action>

        <action name="displayOrderDetail" class="presentation.OrderDetailAction" method='displayOrderDetail'>
            <result name="success">OrderDetail.jsp</result>
        </action>

        <action name="displayCreateOrderDetail" class="presentation.OrderDetailAction" method='displayCreate'>
            <result name="success">CreateOrderDetail.jsp</result>
        </action>

        <action name="createOrderDetail" class="presentation.OrderDetailAction" method='create'>
            <result name="success" type="chain">getOrderDetails</result>
            <result name="input">CreateOrderDetail.jsp</result>
            <result name="error">CreateOrderDetail.jsp</result>
        </action>   

        <action name="displayEditOrderDetail" class="presentation.OrderDetailAction" method='displayUpdate'>
            <result name="success">EditOrderDetail.jsp</result>
        </action>

        <action name="editOrderDetail" class="presentation.OrderDetailAction" method='update'>
            <result name="success" type="chain">getOrderDetails</result>
            <result name="input">EditOrderDetail.jsp</result>
            <result name="error">EditOrderDetail.jsp</result>
        </action>

        <action name="deleteOrderDetail" class="presentation.OrderDetailAction" method='delete'>
            <result name="success" type="chain">getOrderDetails</result>
        </action>
// some more stuff here
</sturts>

输入看起来与JSP之间没有区别:

    <input name="action:displayEditOrderDetail"  class="btn btn-success" value="Edit" type="submit" id="displayOrderDetail_displayEditOrderDetail"/>
    <input name="action:deleteOrderDetail" class="btn btn-danger" value="Delete" type="submit" id="displayOrderDetail_deleteOrderDetail"/>
    <input name="action:getOrderDetails" class="btn btn-default" value="Cancel" type="submit" id="displayOrderDetail_getOrderDetails"/>

对于每个其他CRUD操作,struts成功调用所有setter。除了删除的情况,它只调用setID()。我应该为删除做些什么吗?

提前致谢。

1 个答案:

答案 0 :(得分:0)

删除对象后,您应返回redirectAction结果。

<result name="success" type="redirectAction">getOrderDetails</result>