I have an Action, called ShowData that recovers data from the database and put it in the jsp.
struts.xml
...
<action name="ShowData" class="foo">
<result>foo.jsp</result>
</action>
...
In the foo.jsp page I have a form and the data that I have obtained with the ShowData action.
foo.jsp
...
<s:form action="DoSomething">
<s:input key="email" />
<s:submit/>
</s:form>
<s:iterator value="data_recovered_in_ShowData">
...
</s:iterator>
...
Now I want to add some validation to data. If the return type of DoSomething is something like this: <result name="input">foo.jsp</result> I will lose the data that I recover in ShowData action, but the validation works perfectly and the previous input of the user and the error will be showed in the jsp page.
On the other hand, I know that I can use chain, to do something like <result name="input" type="chain">ShowData</result> and then use MessageStoreInterceptor to recover the data (but I still don’t know how to recover the previous data that the user had introduced in the input). But this is a solution that I’m trying to avoid since I read that using chain is not a good idea.
So then, how do I add some validation in this case without losing any data and without using chain?
If your concern is just retrieving DB data in the first action you have a few options.
Preparableand have both actions retrieve the data using the appropriate service.preparemethod from a superclass.If your concern is previous form data (not indicated in the question) then you have similar options:
There are likely a few other options for either scenario as well.
Ultimately, if you’re using chain only for data retrieval, that’s a bad idea–that’s precisely the scenario that
Preparableis for, and eliminates the coupling between actions.