You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@struts.apache.org by David Geary <sa...@tri-lakesonline.net> on 2000/06/19 19:07:55 UTC

ActionForward Proposal (was Re: Change to Action.perform() signature?)

Robert.Claeson@brightid.se wrote:

> Having the Action classes return a context-relative URI is almost exactly
> what I do in my framework, only that I don't return real URI's but rather
> logical view names (nulls are ok for the reason you cite). I then map
> those logical views to real URIs in a ViewProcessor class that the
> controller servlet use, after which the servlet does the forwarding.

I too have a home-grown framework that does this. I'd like to see
ActionForward use a logical name instead of an actual URI. The logical name
could be mapped through entries in a forward.xml file. Not only does this
approach eliminate URI hard coding, but forward.xml has a nice design
symmetry with action.xml.

If ActionForward stays the way it is, I will wind up implementing my own
ActionForward factory that instantiates ActionForward instances given a
logical name. The factory will look up the actual URI from an XML file and
use that to instantiate ActionForward instances. I would imagine that other
developers like Robert will do something similar, so we might as well have it
in Struts to begin with.


david


Re: ActionForward Proposal (was Re: Change to Action.perform() signature?)

Posted by "Craig R. McClanahan" <Cr...@eng.sun.com>.
David Geary wrote:

> Robert.Claeson@brightid.se wrote:
>
> > Having the Action classes return a context-relative URI is almost exactly
> > what I do in my framework, only that I don't return real URI's but rather
> > logical view names (nulls are ok for the reason you cite). I then map
> > those logical views to real URIs in a ViewProcessor class that the
> > controller servlet use, after which the servlet does the forwarding.
>
> I too have a home-grown framework that does this. I'd like to see
> ActionForward use a logical name instead of an actual URI. The logical name
> could be mapped through entries in a forward.xml file. Not only does this
> approach eliminate URI hard coding, but forward.xml has a nice design
> symmetry with action.xml.
>
> If ActionForward stays the way it is, I will wind up implementing my own
> ActionForward factory that instantiates ActionForward instances given a
> logical name. The factory will look up the actual URI from an XML file and
> use that to instantiate ActionForward instances. I would imagine that other
> developers like Robert will do something similar, so we might as well have it
> in Struts to begin with.
>

I haven't updated the documentation yet to reflect it, but I would submit that
the current code base does in fact support logical lookup of forward entries.

Consider the action.xml entry for the "/logon" path.  Currently, it has the
following contents:

    <action path="/logon" ... other attributes ... >
        <forward name="logon" path="/logon.jsp"/>
        <forward name="success" path="/mainMenu.jsp"/>
    </action>

The nested <forward> elements are used to create a lookup table for ActionForward
entries, based on the logical name you have assigned.  Thus, in the action class
after you validate that the user credentials are correct, you execute:

    return (actionMapping.findForward("success"));

to do a logical lookup on the name "success" -- which ends up forwarding to
/mainMenu.jsp with the configuration file as shown.  You can have as many
<forward> elements as you want, using logical names that are private to this
particular <action> entry.  The names of the forwards for each action mapping do
not have to be the same, which makes this approach nicer than extending the
ActionMappingBase class with additional properties.

I'm also going to be adding a capability for global logical forwards -- for
things that are used across multiple action classes.  You'll be calling
servlet.findForward() instead of actionMapping.findForward() to grab those, but
it's the same idea -- as many logical names as you want.

>
> david

Craig McClanahan