You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Alex Paransky <ap...@standardset.com> on 2002/03/05 09:47:37 UTC
A possible solution for form loading, any comments???
To me, an action should be able to load and execute the form. Furthermore,
I don't want to create separate action classes to load or execute the form.
So here is what I did:
public abstract class FormAction extends Action {
public ActionForward executeForm(...) {.load form.}
public ActionForward loadForm(...) {.execute form.}
public ActionForward execute(...) {
return
"load".equals(mapping.getParameter())
? executeLoad(mapping, form, request, response)
: executeForm(mapping, form, request, response);
}
}
In short, I create two actions in the struts-config.xml. Both are using the
same class which extends from FormAction. One action is configured with
parameter="load" and validate="false". The other action does not have
parameter or validate settings, however, uses the first action as the input
or failure forward.
<action
path="/private/request/createDirectForm"
type="com.myprofiles.client.web.request.CreateDirectAction"
name="createRequestForm"
scope="request"
input="/private/request/createDirect.html"
validate="false"
parameter="load"
/>
<action
path="/private/request/createDirectAction"
type="com.myprofiles.client.web.request.CreateDirectAction"
name="createRequestForm"
scope="request"
input="/private/request/createDirectForm.do"
>
<forward name="success" path="/returnToPop.do" redirect="true" />
<forward name="failure" path="/private/request/createDirectForm.do" />
</action>
Here is what this buys me:
1. The load and the execute are in the same action class so they can share
common members.
2. There is now a standard method to populate the form with data prior to
user entry.
Does anyone have any comments regarding this? Am I going to get in trouble
by using the "parameter=" attribute?
Thanks.
-AP_
-AP_
http://www.alexparansky.com
Java/J2EE Architect/Consultant
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>