Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to pass parameters of type List between actions?
    text
    copied!<p>I have a form which has a single check box, users need to select some of the options and choose one of the provided buttons. Two of the buttons should return the selected options to the same action (First Action) that triggered the page and the other button needs to send the options to another action (Next Action). </p> <p>As I could not define two separate forms for a single check box, currently I am redirecting all the buttons to the First Action and try to redirect to Next Action from there. Therefore I am using the param tag to pass the required variable but I cant access it in my second action.</p> <p>Goal is to have three separate submit buttons for a single check box.</p> <p>I have compared my code with <a href="https://stackoverflow.com/questions/784527/struts-2-parameters-between-actions">this</a>, although they seem to be the same but mine does not work. </p> <p><strong>Form</strong></p> <pre><code> &lt;form name="FirstActionFrom" method="POST" action="doActions"&gt; Check box goes here &lt;input id="ThisBtn1" type="submit" name="req" value="This1"/&gt;&amp;nbsp &lt;input id="ThisBtn2" type="submit" name="req" value="This2"/&gt; &lt;input id="NextBtn" type="submit" name="req" value="Next"/&gt; &lt;/form&gt; </code></pre> <p><strong>First Action:</strong></p> <pre><code>..... private List&lt;Long&gt; selectedOptions; { System.err.println("size of options:" + this.selectedOptions.size()); if req is equal to Next then return "NextAction" else do whatever is required } getter and setter go here } </code></pre> <p><strong>Struts.xml</strong></p> <pre><code> &lt;result name="NextAction" type="redirectAction"&gt; &lt;param name="actionName"&gt;NextAction&lt;/param&gt; &lt;param name="namespace"&gt;/Users/Next&lt;/param&gt; &lt;param name="selectedOptions"&gt;${selectedOptions}&lt;/param&gt; &lt;/result&gt; </code></pre> <p><strong>Next Action</strong></p> <pre><code>..... private List&lt;Long&gt; selectedOptions; ... { System.err.println("size of options:" + this.selectedOptions.size()); &lt;&lt;Always shows Zero return "showThis" } getter and setter go here } </code></pre> <p><strong>Result after selecting a single option</strong> </p> <pre><code>SEVERE : size of options:1 SEVERE : size of options:0 </code></pre>
 

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