This is a very good question. The JavaBeans in and out of the business layer and further down the data persistence layer are so called Data Transfer Objects. They sometimes overlap in terms of attributes a great deal with action forms that correspond to Web page forms. It's not good to use the action form beans as DTO objects, neither is it elegant to use DTO objects as action form beans. One way to structure the code is to define some base abstract classes with the common attributes and put these classes in a com.xxx.yyy.common package and these packages either belong to a separate utility jar or the business tier jar. Both the DTO classes and the action form bean classes will inherit from the abstract base class and add any more properties of their own.I would love to see more discussions on this.

解决方案 »

  1.   

    txranger,if u use struts actionform,your action form should extend org.apache.struts.action.ActionForm,how can they inherit from "the abstract base class "?
      

  2.   

    冗余没有关系 主要是开发和维护的时候的一致性, 这个可以通过在xdoclet 这样就做到只维护一个实体,FormBean通过Entity + xdoclet生成。
      

  3.   

    > txranger,if u use struts actionform,your action form should extend org.apache.struts.action.ActionForm,how can they inherit from "the abstract base class "?Oops. Good catch. I forgot about that. I still use a model-2 framework of my own that I came up with well before Struts came along. I didn't have ActionForm base class as Struts does. So that's how I structured my code.> 冗余没有关系 主要是开发和维护的时候的一致性, 这个可以通过在xdoclet 这样就做到只维护一个实体,FormBean通过Entity + xdoclet生成。This is a reasonable approach.
      

  4.   

    看来没有什么优雅点的方法来构造了,也许只有用getdown的方法。
      

  5.   

    多少并不单是工作量的问题啊,2分数据维护起来也容易出错的,我现在决定让model依赖于org.apache.struts.action.ActionForm,这确实不太好,我想这是struts不对,hibernate就不需要任何接口要继承(这也是他们一再提到的,呵呵)。
      

  6.   

    public class AgentInforForm extends org.apache.struts.action.ActionForm{
      protected  AgentInfor  agentinfor =new AgentInfor ();
      public   AgentInfor  getAgentInfor(){ 
          return agentInfor  ;
      } 
      public setAgentInfor(AgentInfor  vo){
          agentinfor =vo;
      }
    }在jsp页面上<html:text property="agentinfor.属性"  />