In a form I use the struts2 action tag to populate a drop down list:
<s:actionerror />
<s:form action="bookactiondispatcher" namespace="/" theme="simple">
<table>
<tr>
<td>Select an action:</td>
<td><s:action name="bookactions" namespace="/"
executeResult="true" /></td>
</tr>
<tr>
<td>Specify search terms:</td>
<td><s:textfield name="searchString" size="44"
required="true" /></td>
</tr>
<tr>
<td><s:submit type="input" value="Voer actie uit" /></td>
</tr>
</table>
</s:form>
The "bookactions" action refers to the following jsp (bookactions.jsp):
<%@ taglib prefix="s" uri="/struts-tags"%>
<s:radio list="bookActions" value="defaultBookAction" name="bookAction"
onclick="setTextFieldVisibility (this.value)" theme="simple" />
As long as I select the select action (there is also an index action) and enter
search terms, there is no problem; the user is taken to the search result page.
However, the code for the bookactiondispatcher action contains a validate
method:
@Override
public void validate ()
{
logger.debug ("Validating an action dispatch ...");
if (bookAction.equals (SEARCH) && (searchString == null ||
searchString.equals ("")))
addActionError (getText ("bookindexer.error.search.nosearchstring"));
}
When the user selects the search action and forgets to specify search terms,
he/she is taken back to the page with the form:
<action name="bookactiondispatcher"
class="be.vlaamsbrabant.bookindexer.actions.BookActionDispatcher">
...
<result name="input">/index.jsp</result>
...
However:
- On the "input result" page the rich control for the possible book actions is
no longer filled up.
- I "see" the contents of index.jsp (with the form), but the URL is
http://.../bookindexer/bookactiondispatcher.action (the url for the form
action.)
I had exactly the same problem in another application. There I removed the
validate method and used a specific error result to redirect the user to an
error page.
How I can still use struts2 validation and have my rich controls
(re-)populated when being redirected through an input result?
-------------
Aan dit bericht kunnen geen rechten worden ontleend. Alle berichten naar dit
professioneel e-mailadres kunnen door de werkgever gelezen worden.
Ondernemingsnummer: 0253.973.219