You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Howard Miller <me...@howardmiller.co.uk> on 2002/10/01 22:21:42 UTC
ActionMapping.getAttribute()
Hi,
Confused again....
short question.... what does the method ActionMapping.getAttribute() do?? The
javadoc for it is a bit terse!
Longer version... I'm working through the struts-example (carefully) this time, and it
keeps turning up - I simply can't see what its for. In particular in
EditRegistrationAction.java it is used to store the RegistrationForm bean that is
created. Why is that done? I would have thought that is a bean is stored in the
request or session scope it would just have a constant value - not this mystery value -
what am I missing?
While on the subject, (and I suspect related) - what does ActionMapping.getScope()
do? I don't get how an Action can have a scope and/or an Attribute. What's the
story??
Howard Miller
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
Re: ActionMapping.getAttribute()
Posted by Eddie Bush <ek...@swbell.net>.
You specify with an action declaration which scope you want your form
bean to be placed in. There is a contract between actions/form beans
that guarantees the form bean to be instantiated before the action is
called (assuming you specified the form to be used in your config). So,
you see, scope is highly relevant (we could elect to put all forms in
request scope, rather than session [ which is the default]). Now,
coupled with this, we have the idea that the user may want to specify
their own key under which the form may be found. I'm not sure exactly
why that's there, but let me take a stab at it (guys, feel free to
correct me!).
Under most circumstances, you don't need to specify a value for
"attribute" because Struts is going to use a given key automatically (I
can't think of what it is right now) to place your bean into <whichever>
scope and retrieve it from that same scope - it's got to have a name and
it has to know under which scope that name is valid :-) Ok, so why not
just use the default all the time? Well, what if you had a bean you
wanted to be used as a form bean? OR - what if you wanted to do
something with a session-stored form ... say you wanted to reference an
attribute of it. Ok, because you have this nifty "attribute" property,
you're able to give a succint name to the form. You can now have Struts
use some custom bean to act like a form (better derive it from
ActionForm though!) or reference a session-scoped form in subsequent
pages to ... output a field, for example. Say it were a user
registration form and it contained their name. You could reference the
form to display their name.
While I'm sure I'm not far off, I'm equally sure someone else can give
better treatment to this :-) Hopefully that helps some. In any case,
it sounds like you're rather new to Struts - I wouldn't bother trying
any advanced features (of which I would say this is one) right off.
Rather, sit down and build up a "teach myself Struts" app and build on
it incrementally - adding (useful) "advanced features" as you go. While
sitting down and learning all of the classes would certainly be a good
exercise too, I think you would gain more (IMHO) from actually building
something.
Howard Miller wrote:
>Thanks Eddie,
>
>That's interesting, *but* what does the attribute of an ActionMapping actually *mean*,
>why would I want to use it?
>
>I think I've completely failed to understand some important concept! I don't see how a
>mapping has a concept of scope when it belongs to an Action, not a FormBean or
>similar.
>
>Howard Miller
>
--
Eddie Bush
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
Re: ActionMapping.getAttribute()
Posted by Howard Miller <me...@howardmiller.co.uk>.
Thanks Eddie,
That's interesting, *but* what does the attribute of an ActionMapping actually *mean*,
why would I want to use it?
I think I've completely failed to understand some important concept! I don't see how a
mapping has a concept of scope when it belongs to an Action, not a FormBean or
similar.
Howard Miller
On 1 Oct 2002 at 16:54, Eddie Bush wrote:
> attribute is an ... attribute (bit confusing) of an ActionMapping. The
> getAttribute() method returns the value of the attribute attribute - or
> the name attribute if the attribute attribute is null. ActionMapping
> actually inherits this from ActonConfig (in o.a.s.config) so the proper
> javadoc for it (if it exist) would be found there.
>
> /**
> * The request-scope or session-scope attribute name under which our
> * form bean is accessed, if it is different from the form bean's
> * specified <code>name</code>.
> */
>
> That's the javadoc comment for the attribute attribute - taken from
> ActionConfig.java. So the attribute attribute, then, specifies the name
> under which we can find the form-bean associated with this action -
> whether it is stored in request or session scope is specified by a
> different attribute - scope.
>
> Questions on this level can most easily be answered by consulting the
> source :-) Go checkout a copy from CVS (if you can) or grab a copy of
> the latest source release (beta 2 - some of it has been updated, but for
> questions such as this it's still valid I believe). I wish they'd do
> nightly source snapshots too ...
>
> Howard Miller wrote:
>
> >Hi,
> >
> >Confused again....
> >
> >short question.... what does the method ActionMapping.getAttribute() do?? The
> >javadoc for it is a bit terse!
> >
> >Longer version... I'm working through the struts-example (carefully) this time, and it
> >keeps turning up - I simply can't see what its for. In particular in
> >EditRegistrationAction.java it is used to store the RegistrationForm bean that is
> >created. Why is that done? I would have thought that is a bean is stored in the
> >request or session scope it would just have a constant value - not this mystery value -
> >what am I missing?
> >
> >While on the subject, (and I suspect related) - what does ActionMapping.getScope()
> >do? I don't get how an Action can have a scope and/or an Attribute. What's the
> >story??
> >
> >Howard Miller
> >
>
> --
> Eddie Bush
>
>
>
>
> --
> To unsubscribe, e-mail: <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>
>
>
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
Re: ActionMapping.getAttribute()
Posted by Eddie Bush <ek...@swbell.net>.
attribute is an ... attribute (bit confusing) of an ActionMapping. The
getAttribute() method returns the value of the attribute attribute - or
the name attribute if the attribute attribute is null. ActionMapping
actually inherits this from ActonConfig (in o.a.s.config) so the proper
javadoc for it (if it exist) would be found there.
/**
* The request-scope or session-scope attribute name under which our
* form bean is accessed, if it is different from the form bean's
* specified <code>name</code>.
*/
That's the javadoc comment for the attribute attribute - taken from
ActionConfig.java. So the attribute attribute, then, specifies the name
under which we can find the form-bean associated with this action -
whether it is stored in request or session scope is specified by a
different attribute - scope.
Questions on this level can most easily be answered by consulting the
source :-) Go checkout a copy from CVS (if you can) or grab a copy of
the latest source release (beta 2 - some of it has been updated, but for
questions such as this it's still valid I believe). I wish they'd do
nightly source snapshots too ...
Howard Miller wrote:
>Hi,
>
>Confused again....
>
>short question.... what does the method ActionMapping.getAttribute() do?? The
>javadoc for it is a bit terse!
>
>Longer version... I'm working through the struts-example (carefully) this time, and it
>keeps turning up - I simply can't see what its for. In particular in
>EditRegistrationAction.java it is used to store the RegistrationForm bean that is
>created. Why is that done? I would have thought that is a bean is stored in the
>request or session scope it would just have a constant value - not this mystery value -
>what am I missing?
>
>While on the subject, (and I suspect related) - what does ActionMapping.getScope()
>do? I don't get how an Action can have a scope and/or an Attribute. What's the
>story??
>
>Howard Miller
>
--
Eddie Bush
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>