You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@struts.apache.org by joaquim <jo...@dei.uc.pt> on 2000/06/29 19:14:46 UTC

Can't figure extending ActionMapping

Sorry if this is dumb...

I don't understand the ideia of extending ActionMapping in the example
application and in the docs. My doubts are the following:

1) Can't see how my app informs struts that I have implemented ActionMapping
or extended ActionMappingBase.

2) In the example ApplicationMapping extends ActionMappingBase by adding two
properties: "success" and "failure".  But the functionality of this is
obscure to me, because I think that the <forward name="success" ...> and
<forward name="failure"...> elements in action.xml do exactly what these
properties were supposed to do. Or is it necessary to have the name in
forward elements as properties of an ActionMapping implementation?

3) If I do write my own ActionMapping implementation how exactly would I
initialize my own properties in action.xml?





-- 
 Joaquim Ramos de Carvalho
Instituto de Historia e Teoria das Ideias / Centro de Informatica e Sistemas
da Universidade de Coimbra. 3049 COIMBRA CODEX PORTUGAL
joaquim@dei.uc.pt



Re: Can't figure extending ActionMapping

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

> Sorry if this is dumb...
>

It's not dumb ... and it's not documented very well.

>
> I don't understand the ideia of extending ActionMapping in the example
> application and in the docs. My doubts are the following:
>
> 1) Can't see how my app informs struts that I have implemented ActionMapping
> or extended ActionMappingBase.
>

You tell Struts that you have done this by setting a servlet initialization
parameter for the ActionServlet instance named "mapping".  The value you enter
here is the fully qualified Java class name for your extended class.

(The same principle applies to extending ActionForward if you need to -- simply
set the "forward" initialization parameter to the fully qualified name of that
class.)

>
> 2) In the example ApplicationMapping extends ActionMappingBase by adding two
> properties: "success" and "failure".  But the functionality of this is
> obscure to me, because I think that the <forward name="success" ...> and
> <forward name="failure"...> elements in action.xml do exactly what these
> properties were supposed to do. Or is it necessary to have the name in
> forward elements as properties of an ActionMapping implementation?
>

You are quite perceptive here.

The original version of the example application used "success" and "failure"
properties to store the URIs of the pages to which an action should forward
under logical conditions named "success" and "failure".  While this approach
works, it is somewhat restrictive, because you have these properties (and only
these properties) on every single mapping entry.

The <forward> mechanism was added to generalize the idea that you might want to
have any number of named "destinations" to which control should be forwarded,
and that you might want a choice between forwarding and redirecting.  Thus, the
need to extend ActionMapping is substantially reduced, although it is still
available in case you want to pass other configuration parameters to your Action
implementation classes that can be defined at configuration time.

In fact, the example application no longer requires the extended
ApplicationMappingBase class, because everything it needed was covered by the
<forward> enhancements.

>
> 3) If I do write my own ActionMapping implementation how exactly would I
> initialize my own properties in action.xml?
>

Let's assume you created a MyActionMapping class that added properties "foo" and
"bar".  In Java programming terms, that means you added four methods to your
class:
    public String getFoo()
    public void setFoo(String foo)
    public String getBar()
    public void setBar(String bar)

to initialize these properties in your <action> entry, simply add attributes
named "foo" and "bar" like this:

    <action path="/mypath" ... foo="new foo value" bar="new bar value"/>

and Struts will match up the attribute names with the corresponding "set"
methods (setFoo() and setBar()), by following the usual JavaBeans naming style
-- start with "set" and capitalize the first letter of the attribute.

>
> --
>  Joaquim Ramos de Carvalho
> Instituto de Historia e Teoria das Ideias / Centro de Informatica e Sistemas
> da Universidade de Coimbra. 3049 COIMBRA CODEX PORTUGAL
> joaquim@dei.uc.pt

Craig McClanahan