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:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to