Note that there are some explanatory texts on larger screens.

plurals
  1. POError in addFieldError with <s:select> in Struts2
    text
    copied!<p>I am new to Struts2, trying to use <code>addFieldError</code> in my form with <code>&lt;s:select&gt;</code> tag. I have a form in which i have to select a value from a drop-down list. First time when this form is shown, the response comes from an Action class, in which i have created a List. In my form i am printing that list in a drop-down using <code>&lt;s:select&gt;</code> tag like this:</p> <pre class="lang-xml prettyprint-override"><code>&lt;s:form action="clientselect"&gt; &lt;h2&gt;Select Client to add the case :&lt;/h2&gt; &lt;table&gt; &lt;s:select list="list" headerKey="-1" headerValue="Select Client" label="Select Client" tooltip="Select the desired client" name="client"&gt; &lt;/s:select&gt; &lt;tr&gt;&lt;td&gt;&lt;s:submit value="Register Case" theme="simple" align="right"/&gt;&lt;/td&gt; &lt;td&gt;&lt;s:reset value="Reset" theme="simple" align="right"/&gt;&lt;/td&gt;&lt;/tr&gt; &lt;/table&gt; &lt;/s:form&gt; </code></pre> <p>"pageinclude=ancar" prints this form.</p> <p>struts.xml</p> <pre class="lang-xml prettyprint-override"><code>&lt;action name="clientselect" class="casediary.JudicialCaseRegisterValidation" method="execute"&gt; &lt;result name="addcase"&gt;user.jsp?pageinclude=ncr&lt;/result&gt; &lt;result name="error"&gt;user.jsp?pageinclude=errancar&lt;/result&gt; &lt;result name="input"&gt;user.jsp?pageinclude=ancar&lt;/result&gt; &lt;result name="loggedout"&gt;index.jsp?pageinclude=relogin&lt;/result&gt; &lt;/action&gt; </code></pre> <p>in JudicialCaseRegisterValidation.java</p> <pre class="lang-java prettyprint-override"><code>public void validate() { if(client==null || client.equals("-1")) addFieldError("client", "This field can not be blank."); } </code></pre> <p>All is working fine. error condition is satisfied and in result i am getting "input". Error message is also printing BUT THE VALUES IN THE DROP-DOWN LIST ARE GONE. THE LIST IS PRINTING EMPTY. Because this time response is not coming from the Action class in which the List is set.</p> <p>then i changed my struts.xml to send the request to the Action class from the <code>&lt;result&gt;</code> like this:</p> <pre><code>&lt;result name="input" type="redirect"&gt;link.action&lt;/result&gt; </code></pre> <p>"link.action" is what that is sending the request in Action class to create the List and printing that form.</p> <p>But this time the form is just printed again &amp; no error message is printed.</p> <p>I want that List be printed again and also the error message besides it. Please Tell How.?</p>
 

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