title: Struts1 and ActionForm inheritance, mess of data
body: <p>I have a problem using Struts1 ActionForm beans. Please, see a part of my struts-config:</p>
  
  <pre><code>&lt;!-- RuleSearchForm is a sublass of RuleForm --&gt;
      form-beans&gt;
              &lt;form-bean name="ruleForm" 
                  type="forms.RuleForm"&gt;
              &lt;/form-bean&gt;
              &lt;form-bean name="ruleSearchForm" 
                  type="forms.RuleSearchForm"&gt;
              &lt;/form-bean&gt;
          &lt;/form-beans&gt;
      &lt;!-- Mappings --&gt;
      &lt;action path="/RuleList" 
              type="actions.RuleList"
              name="ruleSearchForm"
              scope="session"
              validate="false"&gt;
          &lt;forward name="success" path="/html/view/RuleList.jsp"&gt;&lt;/forward&gt;
      &lt;/action&gt;
      &lt;action path="/RuleCreate" 
              type="actions.RuleCreate" 
              name="ruleForm" 
              scope="request" 
              validate="false"&gt;
          &lt;forward name="success" path="/html/view/CreateUpdateRule.jsp"&gt;&lt;/forward&gt;
      &lt;/action&gt;
  </code></pre>
  
  <p>And parts of my Actionform beans code:</p>
  
  <pre><code>public class RuleForm extends ActionForm {
      protected Integer   crid;       
      protected List levels;        
      /** Some other fileds go here */
  
      public Collection getLevels(){
          if(levels == null){
              levels = DAOClass.getLevels();
              Collections.reverse(levels);
          }
          return levels;
      }
  
      /** Other getters/setters go here */
  }
  
  public class RuleSearchForm extends RuleForm{
  
      /**
       * Avoid filter reset. If needs to be reset use {@link RuleForm#resetBeanFields()} directly.
       * */
      public void reset(ActionMapping mapping, HttpServletRequest request) {
  
      }
  
      /**
       * Add empty value. User should have an opportunity not to set value for this field.
       * */
      public Collection getLevels(){
          if(levels == null || levels.size() == 0){
              super.getLevels();
              levels.add(0, new Level());
          }
          return levels;
      }
  }
  </code></pre>
  
  <p>The problem is: </p>
  
  <ol>
  <li><p>User goes to /RuleList.do and sees the list of rules. <strong>ruleSearchForm</strong> used as a bean for transferring search params to /RulesList.do action. Initially tihs bean is empty, only getLevels() returns "empty value" + list of levels got from superclass method.</p></li>
  <li><p>User goes to /CreateRule.do, <strong>ruleForm</strong> is used for collecting user input. <strong>levels</strong> property  is used in selectbox. And I get there list of levels + empty row. This empty row is not added in RuleForm (named ruleForm). It's added it subclass of RuleForm.  Why does super class ActionForm bean with NO static fields, with other name gets values from it's sublass instance???</p></li>
  <li><p>If users saves Rule and has been redirected to /RuleList.do, the he sees populated (i.e. filled) search form ("ruleSearchForm") with values from "ruleForm". </p></li>
  </ol>
  
  <p>What does it mean? Please help, I don't understand this mess of data beetween ActionForm Beans</p>
  
  <p>UPD:
  Now, I've changed inheritance of FormAction beans. I've introduced BaseFormBean. This BaseFormBean got two children: RuleForm and RuleSearchForm. 
  It didn't help. Still attributes from one bean are moved to another.</p>
  
  <p><em>My jsp code:</em>
  <strong>CreateUpdateRule.jsp:</strong></p>
  
  <pre><code>&lt;html:form action="/RuleSave.do"&gt;
  &lt;html:hidden property="crid"/&gt;
  &lt;table border="0" cellpadding="2" cellspacing="0"&gt;
      &lt;tr&gt;
          &lt;td&gt;&lt;bean:message key="rule.levelId"/&gt;&lt;/td&gt;
          &lt;td&gt;&lt;html:select property="levelId"&gt;
                  &lt;html:optionsCollection  property="levels" value="clid" label="name" /&gt;
              &lt;/html:select&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td&gt;&lt;bean:message key="rule.timeStart"/&gt;&lt;/td&gt;
          &lt;td&gt;&lt;html:text property="timeStartStr"/&gt;&lt;/td&gt;
      &lt;/tr&gt;   
      &lt;tr&gt;
          &lt;td&gt;&lt;bean:message key="rule.timeEnd"/&gt;&lt;/td&gt;
          &lt;td&gt;&lt;html:text property="timeEndStr"/&gt;&lt;/td&gt;
      &lt;/tr&gt;   
  
      &lt;tr&gt;
          &lt;td&gt;
              &lt;html:submit styleClass="wpsButtonText"&gt;&lt;bean:message key="application.submit"/&gt;&lt;/html:submit&gt;
          &lt;/td&gt;
          &lt;td&gt;
              &lt;input type="button" onclick="cancelOperation()" class="wpsButtonText" value="&lt;bean:message key="application.cancel"/&gt;" /&gt;
              &lt;html:link styleClass="cancelLink" page="/RuleList.do"&gt;&lt;/html:link&gt;
          &lt;/td&gt;
      &lt;/tr&gt;
  &lt;/table
  &lt;/html:form&gt;
  </code></pre>
  
  <p><strong>my RuleList.jsp:</strong></p>
  
  <pre><code>&lt;html:form action="/CritRuleList.do" &gt;
  &lt;table style="width: 100%;"&gt;
      &lt;tr&gt;
          &lt;td&gt;&lt;bean:message key="rule.levelId"/&gt;&lt;/td&gt;
          &lt;td&gt;&lt;html:select property=levelId"&gt;
                  &lt;html:optionsCollection  property="levels" value="clid" label="name" /&gt;
              &lt;/html:select&gt;
          &lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;    
          &lt;td&gt;&lt;bean:message key="rule.timeStart"/&gt;&lt;/td&gt;
          &lt;td&gt;&lt;html:text property="timeStartStr" /&gt;&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;    
          &lt;td&gt;&lt;bean:message key="rule.timeEnd"/&gt;&lt;/td&gt;
          &lt;td&gt;&lt;html:text property="timeEndStr" /&gt;&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;    
          &lt;td colspan="2"&gt;
              &lt;html:submit styleClass="wpsButtonText"&gt;&lt;bean:message key="application.search"/&gt;&lt;/html:submit&gt;
              &lt;input type="button" onclick="cancelOperation(this)" class="wpsButtonText" value="&lt;bean:message key="critrule.searchClear"/&gt;" /&gt;
              &lt;html:link styleClass="cancelLink" page="/RuleResetSearchFilter.do"&gt;&lt;/html:link&gt;
          &lt;/td&gt;   
      &lt;/tr&gt;
  &lt;/table&gt;    
  &lt;/html:form&gt;
  </code></pre>