This is my first web app with Struts, so please be gentle :-)
I am trying to implement the following pattern:
On GET:
- Populate a form with fields OR show an empty form - Show the form
On POST:
- Validate the form, show it again if it has errors.
Very basic, but yet, I can't find the correct way to do this with Struts.
I have not seen one piece of example code that looks at the request method to make the distinction between showing the initial empty form (GET) or processing it (POST).
In my code I do basically this:
execute() { if (request.getMethod().compareTo("GET") == 0) { ... code to setup the session ... return mapping.findForward("AddRecord"); // Shows the form }
if (request.getMethod().compareTo("POST") == 0)
{
... execute some business logic ...
return mapping.findForward("Success"); // Goes back to were we came from
}
}
But the problem here is that when I forward to the AddRecord forward, the form is validated, which in case of an empty initial form will show errors for each field. I can set validate to false in my action definition but then validation is also skipped when I need it.
The forward is defined like this:
<forward name="AddRecord" path="/addrecord.jsp" redirect="false"/>
This must be very basic, but it is very difficult to find a clear answer in the large amount of Struts related resources :-/
S.
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]