You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by rob <ro...@fastmail.fm> on 2002/02/07 14:18:09 UTC

ActionForward usage.

Regarding a post Ted made a couple of days ago. (Which a copy of follows
this post)
As well as some other general questions.

I would like to pre-populate my form field values from a database
datasource.

I am using the following configuration which to be honest is giving me a bit
of a
headache and I hope someone could improve it for me.

<action path="/addItem"
    type="actions.AddItemAction"
    name="AddItemForm"
    scope="request"
    input="/pages/addItem.jsp"
    validate="true">

    <forward name="self"    path="/pages/addItem.jsp"/>

</action>

Initially if I want to add an item I forward to /addItem the AddItemAction
detects whether or not this is the first visit to the form and if so places
data from an rdbms into the HttpServletRequest object and calls the
ActionForm (AddItemForm)'s reset() method to populate the form.

The AddItemAction then forwards the request to the "self" forward which
displays the form for the user to enter his or her own new data.  The user
then submits the form back to the /do/addItem and this time the action
detects that the form had been prepopulated and that the data should be
validated and inserted into the rdbms upon completion the AddItemAction then
forwards the request to some global forward.

Now at a first glance this obviously sucks.   A couple of days ago however I
saw a post that Ted had made about mapping all request through actions that
I thought might help me to solve the above problem. (the post attached
below)

>From the configuration in Ted's post I developed this new configuration
(which doesn't work).
I set it up initially with the intent that I would subclass the
ForwardAction class and have it pull the data from the rdbms stick the data
in the request and then call the forms reset() method to populate the form.
However before getting around to that I figured I'd just try setting it up
to forward to see if I ended up at my addItem.jsp form.

<action path="/addItemGet"
    type="org.apache.struts.actions.ForwardAction"
    parameter="/pages/addItem.jsp">
    name="AddItemForm"
    scope="request"
    validate="false"
</action>

<action path="/addItemSet"
    type="actions.AddItemAction"
    name="AddItemForm"
    scope="request"
    validate="true"
    input="/pages/addItem.jsp">

</action>

Unfortunately this is the error I get:

elysium# 2002-02-08 09:56:37 - Ctx(/ims) : Status code:500 request:R( /ims +
/do + /addItemGet) msg:No action instance for path /addItemGet could be
created

I've posted about form pre-population before and a couple of you were able
to help me out but clearly I misunderstood.  So please if you reply be as
verbose and explanitory as possible thanks.

>The best practice now is to use ActionMappings for everything, so that
>the reqeust passes through the controller.
>
>This buys you several important capabilities that become important as
>applications grow. Not the least of which is the new support for
>multiple applications in the Nightly Build.
>
>The ActionMapping has a validate property that you can use to turn off
>validation when the mapping is used to initialize a new form. So,
>typically, you will have an ActionMapping for each circumstance.
>
>            <action
>                path="/item/Add"
>                type="org.apache.struts.actions.ForwardAction"
>        parameter="/pages/item/Form.jsp">
>                name="itemForm"
>                scope="request"
>                validate="false">
>            </action>
>
>           <action
>                path="/item/Store"
>                type="org.apache.gavel.item.http.Store"
>                name="itemForm"
>                scope="request"
>                validate="true"
>                input="/pages/item/Form.jsp"">
>                <forward
>                    name="continue"
>                    path="/do/donor/Detail"/>
>            </action>



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>