title: Using ModelDriven in Struts 2
body: <p>I am developing a project using Hibernate, Struts 2 and Spring, but my problems are with Struts.</p>
  <p>I have created 3 classes extending <code>ActionSupport</code> and are implementing <code>ModelDriven</code> for the same class in all of them. I have implemented some methods to be executed when the actions are called.</p>
  <p>The structure for the classes is like</p>
  <p><strong>Class1Action.java:</strong></p>
  <pre><code>public class Class1Action extends ActionSupport implements ModelDriven&lt;ModelDrivenClass&gt; {
  
       private ModelDrivenClass modelDrivenClass;
  
  
       // getter and setter for modelDrivenClass
  
       public String methodName() {
  
       System.out.println(&quot;Entrou!&quot;);
  
          return SUCCESS;
  
      }
  
      @Override
      public Sensor getModel() {
          return getSensor();
      }
  
  }
  </code></pre>
  <p>In <code>struts.xml</code> I have created 3 action using the next structure</p>
  <p><strong>struts.xml:</strong></p>
  <pre><code>&lt;action name=&quot;actionName1&quot; method=&quot;methodName&quot; class=&quot;Class1Action&quot;&gt;
     &lt;interceptor-ref name=&quot;validation&quot;&gt;
        &lt;param name=&quot;excludeMethods&quot;&gt;methodName&lt;/param&gt;
     &lt;/interceptor-ref&gt;
     &lt;result name=&quot;success&quot; &gt;success.jsp&lt;/result&gt;
     &lt;result name=&quot;input&quot; &gt;input.jsp&lt;/result&gt;
  &lt;/action&gt;
  </code></pre>
  <p>Besides that I have a JSP with 3 buttons referring the different Struts actions, and several fields that represents fields from the model driven class used in the 3 action classes, and all of the fields inside a <code>&lt;s:push&gt;</code> tag.</p>
  <p>The problem is when I am populating the fields and just after click on any of the buttons, data in the fields are missing.</p>
  <p>I have tried to remove the 3 Struts lines that excludes the methods from validation, but instead of the fields are being empty, at the second time I have pressed the same button he returns an input and redirects to input.jsp.</p>
  <p>The next code is from <code>success.jsp</code>, that is the starting page:</p>
  <p><strong>success.jsp:</strong></p>
  <pre><code>&lt;form method=&quot;post&quot; &gt;
      
      
      &lt;s:push value=&quot;modelDrivenClass&quot;&gt;
  
          &lt;s:textfield label=&quot;FieldLabel1&quot; name=&quot;modelDrivenClassAttribute1&quot; /&gt;
          &lt;s:textfield label=&quot;FieldLabel2&quot; name=&quot;modelDrivenClassAttribute2&quot; /&gt;
          &lt;s:textfield label=&quot;FieldLabel3&quot; name=&quot;modelDrivenClassAttribute3&quot; /&gt;
          &lt;s:textfield label=&quot;FieldLabel4&quot; name=&quot;modelDrivenClassAttribute4&quot; /&gt;
          &lt;s:textfield label=&quot;FieldLabel5&quot; name=&quot;modelDrivenClassAttribute5&quot; /&gt;
              
      &lt;/s:push&gt;
      
      
  &lt;s:submit action=&quot;actionName1&quot; name=&quot;Submit1&quot; value=&quot;Submit1&quot; /&gt;
  &lt;s:submit action=&quot;actionName2&quot; name=&quot;Submit2&quot; value=&quot;Submit2&quot; /&gt;
  &lt;s:submit action=&quot;actionName3&quot; name=&quot;Submit3&quot; value=&quot;Submit3&quot; /&gt;
  &lt;/form&gt;
  </code></pre>
  <p>I don't know if is this the right way to do it, but I made it work when I used only one class implementing <code>ModelDriven</code> and this class has all the 3 methods.</p>
  <p>I am just trying this way because I would like to let my code clear and don't have all methods in only one class.</p>