You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by "Ing. Andrea Vettori" <ma...@andreavettori.com> on 2006/11/08 08:56:52 UTC
Struts2 question on action with properties
Hi,
I've used struts1 a lot and now I'm using struts2 version 2.0.1 for a
new medium-sized project (it's an e-commerce site).
I'm facing this problem and since the documentation is poor (or at
least it seems poor, maybe I'm looking on the wrong places), I need
an advice from you experts.
In the home page, that is a jsp page loaded with the "Home" action, I
have a couple of forms. In one of them I need to use a select tag to
give the user some options. I've put the List getInfos() method on
the Action specified on the form that contains the select tag since I
thought that an Action would be instanciated and used to call the
method. This gives me an error saying that the list param of the
select tag is not found as a collection/array/..... etc.
Putting the getInfos() method on the Home action, that is the action
that call the jsp page where the form is, works.
Now I think it would be "cleaner" if the getInfos() method belonged
to the Action that is associated to the form. Is this possible to
do ? Am I missing something ?
Thank you
P.S.
Hope you understand my Italian-English :)
--
Ing. Andrea Vettori
Consulente per l'Information Technology
Re: Struts2 question on action with properties
Posted by "Ing. Andrea Vettori" <ma...@andreavettori.com>.
Ok I understand.
What I'm missing is that when the form is displayed the Action is not
yet istantiated so no methods can be called. If you want to call a
method of that Action you must instantiate it with the action tag.
Thanks
Il giorno 10/nov/06, alle ore 00:15, Ted Husted ha scritto:
> The typical approach is to place an input method on the "Action that
> is associated to the form". To display the method, you can refer to
> "action_input" and then to submit the action you can refer to just
> "action". If you want to avoid defining two action elements, you can
> use wildcards.
>
> <action name="action_*" method="{1}" class="...">
--
Ing. Andrea Vettori
Consulente per l'Information Technology
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Struts2 question on action with properties
Posted by Ted Husted <hu...@apache.org>.
The typical approach is to place an input method on the "Action that
is associated to the form". To display the method, you can refer to
"action_input" and then to submit the action you can refer to just
"action". If you want to avoid defining two action elements, you can
use wildcards.
<action name="action_*" method="{1}" class="...">
Now, action_input will fire the "input" method on the Action class,
and action_cancel would fire the "cancel" method. Just plain "action"
will fall back to the default "execute" method.
If the list needs to be retrieved from a database or such, have the
Action class implement preparable, and then put the list builidng code
in a method named "prepare".
If more than one page needs to display the list, then a typical
approach is to create a base Support class that other Action classes
can extend. Put the shared properties on the Support class, so that
any Action can use them.
The documentation we have starts here:
* http://cwiki.apache.org/WW/home.html
Be sure to go through the MailReader application, which handles
several common use cases. Pursuing the ShowCase is also instructive.
and we now have links that show all the Showcase source code in real
time.
While written for a prior version, the WebWork In Action book is also
quite good, and everything in there applies to Struts 2.
-- HTH, Ted.
* http://www.husted.com/struts/
On 11/8/06, Ing. Andrea Vettori <ma...@andreavettori.com> wrote:
> Hi,
>
> I've used struts1 a lot and now I'm using struts2 version 2.0.1 for a
> new medium-sized project (it's an e-commerce site).
>
> I'm facing this problem and since the documentation is poor (or at
> least it seems poor, maybe I'm looking on the wrong places), I need
> an advice from you experts.
>
> In the home page, that is a jsp page loaded with the "Home" action, I
> have a couple of forms. In one of them I need to use a select tag to
> give the user some options. I've put the List getInfos() method on
> the Action specified on the form that contains the select tag since I
> thought that an Action would be instanciated and used to call the
> method. This gives me an error saying that the list param of the
> select tag is not found as a collection/array/..... etc.
>
> Putting the getInfos() method on the Home action, that is the action
> that call the jsp page where the form is, works.
>
> Now I think it would be "cleaner" if the getInfos() method belonged
> to the Action that is associated to the form. Is this possible to
> do ? Am I missing something ?
>
> Thank you
>
> P.S.
> Hope you understand my Italian-English :)
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org