Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Pretty much everyone starting with Struts2 encounter this problem, soon or later.</p> <p>When requesting an Action in Struts2, your request will pass <a href="http://struts.apache.org/development/2.x/docs/interceptors.html" rel="nofollow">through an Interceptor Stack</a> (a list of Interceptors); every Interceptor does is particular business, then redirect the request (in case of errors) or proceed the execution to the next Interceptor, or to the Action if it is the last.</p> <p>The validation is performed by the Validation Interceptor. If the validation fails, it will <em>hijack</em> the request and will redirect it to the <strong>input</strong> result defined in struts.xml. No matter if the validation is by <strong><em>XML</em></strong>, by <strong><em>Annotation</em></strong> or in a <strong><em>validate()</em></strong> method inside the Action: <strong>the Action is not reached !</strong> Then, everything inside the <code>execute()</code> method, or the method you are calling (if you are using a custom one) is not executed;</p> <p>If the loading of your List elements is demanded to the <code>execute()</code> method, it won't be performed in case of an <strong>input</strong> result.</p> <p>The main ways to avoid this problem are:</p> <ol> <li><p>Implement <a href="http://struts.apache.org/release/2.3.x/docs/preparable-interface.html" rel="nofollow">Preparable Interface</a>, and put all the data loading stuff into the prepare() method. <br/>That method is run by the Prepare Interceptor, that is placed BEFORE the Validation Interceptor; <br/>it will <em>always</em> run, and it will run <em>before</em> the validation, no matter which method of your action (<code>execute()</code> or something else) you are calling, nor if you are encountering validation errors;</p></li> <li><p>Use <code>&lt;s:action/&gt;</code> tag from the JSP, to call dummy Actions returning JSP snippets;</p></li> <li><p>Use a <code>redirectAction</code> as the <strong>input</strong> result type, to the <code>execute()</code> (or something else) method, as you are doing. <br/>While redirecting, it will lose all the request parameters (including action errors, field errors, action messages etc) , then you will need to manually copy them by declaring them in the struts.xml as parameters of the <code>redirectAction</code> result.</p></li> </ol> <p>The first way is the preferred, imho.</p> <p>EDIT: </p> <p>just found it in the official documentation too: <a href="http://struts.apache.org/development/2.x/docs/how-do-we-repopulate-controls-when-validation-fails.html" rel="nofollow">how do we repopulate controls when validation fails ?</a> </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload