You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by hareendra seneviratne <ha...@gmail.com> on 2010/09/27 13:24:55 UTC
Accessing User input in execute ( ) method
Hi all,
I’m new to struts and getting to know it.
Is it mandatory to have an ActionForm? Can we access the variables defined
in *view* from *execute()* method without using an ActionForm?
Thnks for ur replies J
Re: Accessing User input in execute ( ) method
Posted by serge nana <na...@gmail.com>.
The MODEL (Persistence, DB) part does not really exist in Struts.
On Tue, Sep 28, 2010 at 5:53 PM, serge nana <na...@gmail.com> wrote:
> Hareendra,
>
> You don't need to have an ActionForm in order to invoke an Action class. An
> ActionForm is a data transfer object (DTO) that allows you to transfer data
> from the view to the controller( in this case your action). So, if you want
> to use struts and you have a form to send to the server, i recommend you to
> use ActionForm.
>
> In the big picture though, an Action class is a Servlet sub-class. Just
> like you can retrieve variables from the request object inside a doXXXX
> method, so you can do the same inside the *execute()* method by calling
> request.getParameter("param_name").
>
> Hope this helps.
>
> "Don't rely on luck to find a bug."
>
>
>
> On Mon, Sep 27, 2010 at 5:24 AM, hareendra seneviratne <
> hareendras@gmail.com> wrote:
>
>> Hi all,
>>
>>
>>
>> I’m new to struts and getting to know it.
>>
>>
>>
>> Is it mandatory to have an ActionForm? Can we access the variables defined
>> in *view* from *execute()* method without using an ActionForm?
>>
>>
>>
>> Thnks for ur replies J
>>
>
>
Re: Accessing User input in execute ( ) method
Posted by Dave Newton <da...@gmail.com>.
So you're using Struts 2?
Dave
On Wed, Sep 29, 2010 at 3:02 AM, hareendra seneviratne <hareendras@gmail.com
> wrote:
> Hi Thank u all for ur replies.
>
> This is my next step...
>
> Here is the source of one of my model classes, Officer
> public class Officer {
> private String id;
> private String error = null;
> private Set<Excess> *totalExcessSet* = new HashSet<Excess>();
> .........
>
> In my execute() method I have an Officer Instance.
> I want to iterate through *totalExcessSet *property of this instance within
> my view. How am I gonna do this??
>
> Many thanks again
>
>
>
>
> On Wed, Sep 29, 2010 at 5:23 AM, serge nana <na...@gmail.com> wrote:
>
> > Hareendra,
> >
> > You don't need to have an ActionForm in order to invoke an Action class.
> An
> > ActionForm is a data transfer object (DTO) that allows you to transfer
> data
> > from the view to the controller( in this case your action). So, if you
> want
> > to use struts and you have a form to send to the server, i recommend you
> to
> > use ActionForm.
> >
> > In the big picture though, an Action class is a Servlet sub-class. Just
> > like
> > you can retrieve variables from the request object inside a doXXXX
> method,
> > so you can do the same inside the *execute()* method by calling
> > request.getParameter("param_name").
> >
> > Hope this helps.
> >
> > "Don't rely on luck to find a bug."
> >
> >
> > On Mon, Sep 27, 2010 at 5:24 AM, hareendra seneviratne <
> > hareendras@gmail.com
> > > wrote:
> >
> > > Hi all,
> > >
> > >
> > >
> > > I’m new to struts and getting to know it.
> > >
> > >
> > >
> > > Is it mandatory to have an ActionForm? Can we access the variables
> > defined
> > > in *view* from *execute()* method without using an ActionForm?
> > >
> > >
> > >
> > > Thnks for ur replies J
> > >
> >
>
Re: Accessing User input in execute ( ) method
Posted by Maurizio Cucchiara <ma...@gmail.com>.
Hareendra,
You should take a look at
http://struts.apache.org/1.x/struts-taglib/tlddoc/logic/iterate.html
Maurizio Cucchiara
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Accessing User input in execute ( ) method
Posted by serge nana <na...@gmail.com>.
You could save the set object into the request object as:
request.setAttribute("officer", new BlahBlahOfficer());
and then use strut Logic tag in your view to iterate through the list as:
<logic:Iterate name="officer" id="Item" property="totalExcessSet">
<logic:Iterate name="Item" id="excess">
<bean:write name="excess"
property="excess_property_name_to_print" />
</logic:Iterate>
</logic>
The list that you pass has to implement an Iterator.
I have not ran the snippet of code above but that is the idea.
On Wed, Sep 29, 2010 at 1:02 AM, hareendra seneviratne <hareendras@gmail.com
> wrote:
> Hi Thank u all for ur replies.
>
> This is my next step...
>
> Here is the source of one of my model classes, Officer
> public class Officer {
> private String id;
> private String error = null;
> private Set<Excess> *totalExcessSet* = new HashSet<Excess>();
> .........
>
> In my execute() method I have an Officer Instance.
> I want to iterate through *totalExcessSet *property of this instance within
> my view. How am I gonna do this??
>
> Many thanks again
>
>
>
>
> On Wed, Sep 29, 2010 at 5:23 AM, serge nana <na...@gmail.com> wrote:
>
> > Hareendra,
> >
> > You don't need to have an ActionForm in order to invoke an Action class.
> An
> > ActionForm is a data transfer object (DTO) that allows you to transfer
> data
> > from the view to the controller( in this case your action). So, if you
> want
> > to use struts and you have a form to send to the server, i recommend you
> to
> > use ActionForm.
> >
> > In the big picture though, an Action class is a Servlet sub-class. Just
> > like
> > you can retrieve variables from the request object inside a doXXXX
> method,
> > so you can do the same inside the *execute()* method by calling
> > request.getParameter("param_name").
> >
> > Hope this helps.
> >
> > "Don't rely on luck to find a bug."
> >
> >
> > On Mon, Sep 27, 2010 at 5:24 AM, hareendra seneviratne <
> > hareendras@gmail.com
> > > wrote:
> >
> > > Hi all,
> > >
> > >
> > >
> > > I’m new to struts and getting to know it.
> > >
> > >
> > >
> > > Is it mandatory to have an ActionForm? Can we access the variables
> > defined
> > > in *view* from *execute()* method without using an ActionForm?
> > >
> > >
> > >
> > > Thnks for ur replies J
> > >
> >
>
Re: Accessing User input in execute ( ) method
Posted by hareendra seneviratne <ha...@gmail.com>.
Hi Thank u all for ur replies.
This is my next step...
Here is the source of one of my model classes, Officer
public class Officer {
private String id;
private String error = null;
private Set<Excess> *totalExcessSet* = new HashSet<Excess>();
.........
In my execute() method I have an Officer Instance.
I want to iterate through *totalExcessSet *property of this instance within
my view. How am I gonna do this??
Many thanks again
On Wed, Sep 29, 2010 at 5:23 AM, serge nana <na...@gmail.com> wrote:
> Hareendra,
>
> You don't need to have an ActionForm in order to invoke an Action class. An
> ActionForm is a data transfer object (DTO) that allows you to transfer data
> from the view to the controller( in this case your action). So, if you want
> to use struts and you have a form to send to the server, i recommend you to
> use ActionForm.
>
> In the big picture though, an Action class is a Servlet sub-class. Just
> like
> you can retrieve variables from the request object inside a doXXXX method,
> so you can do the same inside the *execute()* method by calling
> request.getParameter("param_name").
>
> Hope this helps.
>
> "Don't rely on luck to find a bug."
>
>
> On Mon, Sep 27, 2010 at 5:24 AM, hareendra seneviratne <
> hareendras@gmail.com
> > wrote:
>
> > Hi all,
> >
> >
> >
> > I’m new to struts and getting to know it.
> >
> >
> >
> > Is it mandatory to have an ActionForm? Can we access the variables
> defined
> > in *view* from *execute()* method without using an ActionForm?
> >
> >
> >
> > Thnks for ur replies J
> >
>
Re: Accessing User input in execute ( ) method
Posted by serge nana <na...@gmail.com>.
Hareendra,
You don't need to have an ActionForm in order to invoke an Action class. An
ActionForm is a data transfer object (DTO) that allows you to transfer data
from the view to the controller( in this case your action). So, if you want
to use struts and you have a form to send to the server, i recommend you to
use ActionForm.
In the big picture though, an Action class is a Servlet sub-class. Just like
you can retrieve variables from the request object inside a doXXXX method,
so you can do the same inside the *execute()* method by calling
request.getParameter("param_name").
Hope this helps.
"Don't rely on luck to find a bug."
On Mon, Sep 27, 2010 at 5:24 AM, hareendra seneviratne <hareendras@gmail.com
> wrote:
> Hi all,
>
>
>
> I’m new to struts and getting to know it.
>
>
>
> Is it mandatory to have an ActionForm? Can we access the variables defined
> in *view* from *execute()* method without using an ActionForm?
>
>
>
> Thnks for ur replies J
>
RE: Accessing User input in execute ( ) method
Posted by adam pinder <ap...@hotmail.co.uk>.
if you're new to struts why don't you use struts2 its far better and less intrusive code wise.
> Date: Tue, 28 Sep 2010 09:03:51 +0530
> Subject: Re: Accessing User input in execute ( ) method
> From: hareendras@gmail.com
> To: user@struts.apache.org
>
> Guys,
>
> Thnks for all replies. I'm using struts 1.2.9. I could use
> request.getParameter() to get the user input. :)
>
> Can you plc advice me on what should be done and what should not be done in
> execute() method. According to my understanding <struts-config> is like a
> router to route the requests. (Plc correct if I'm wrong) For each action the
> execute() method is acting like a controller. Am I correct? If not can u
> guys plc explain the Model View and the Controller in struts.
> Thanks
>
> PS: I'm new to struts and hope u guys don't mind me asking basic things :)
>
>
>
> On Mon, Sep 27, 2010 at 6:27 PM, Kushan Jayathilake <ku...@gmail.com>wrote:
>
> > yeah lol...
> >
> > --
> > Regards
> > Kushan Jayathilake
> >
> >
> > On Mon, Sep 27, 2010 at 6:21 PM, Dave Newton <da...@gmail.com>
> > wrote:
> >
> > > We're all making an assumption the OP is talking about Struts 2; I made
> > an
> > > assumption the opposite way.
> > >
> > > Let's just ask--Hareendra, what version of Struts are you asking about?
> > >
> > > Dave
> > >
> > > On Mon, Sep 27, 2010 at 8:45 AM, Li Ying <li...@gmail.com>
> > wrote:
> > >
> > > > Hi hareendra :
> > > >
> > > > You don't need an ActionForm to capture the variables sent by client
> > > > request.
> > > >
> > > > What you used to defined in ActionForm class, is now should be defined
> > in
> > > > Action class.
> > > >
> > > > You can read more detail information in
> > > > http://struts.apache.org/2.2.1/docs/comparing-struts-1-and-2.html
> > > > (section [Harvesting Input])
> > > > about this issue.
> > > >
> > > > Hope this help you.
> > > >
> > > >
> > > > 2010/9/27 hareendra seneviratne <ha...@gmail.com>
> > > >
> > > > > Hi all,
> > > > >
> > > > >
> > > > >
> > > > > I’m new to struts and getting to know it.
> > > > >
> > > > >
> > > > >
> > > > > Is it mandatory to have an ActionForm? Can we access the variables
> > > > defined
> > > > > in *view* from *execute()* method without using an ActionForm?
> > > > >
> > > > >
> > > > >
> > > > > Thnks for ur replies J
> > > > >
> > > >
> > >
> >
Re: Accessing User input in execute ( ) method
Posted by hareendra seneviratne <ha...@gmail.com>.
Guys,
Thnks for all replies. I'm using struts 1.2.9. I could use
request.getParameter() to get the user input. :)
Can you plc advice me on what should be done and what should not be done in
execute() method. According to my understanding <struts-config> is like a
router to route the requests. (Plc correct if I'm wrong) For each action the
execute() method is acting like a controller. Am I correct? If not can u
guys plc explain the Model View and the Controller in struts.
Thanks
PS: I'm new to struts and hope u guys don't mind me asking basic things :)
On Mon, Sep 27, 2010 at 6:27 PM, Kushan Jayathilake <ku...@gmail.com>wrote:
> yeah lol...
>
> --
> Regards
> Kushan Jayathilake
>
>
> On Mon, Sep 27, 2010 at 6:21 PM, Dave Newton <da...@gmail.com>
> wrote:
>
> > We're all making an assumption the OP is talking about Struts 2; I made
> an
> > assumption the opposite way.
> >
> > Let's just ask--Hareendra, what version of Struts are you asking about?
> >
> > Dave
> >
> > On Mon, Sep 27, 2010 at 8:45 AM, Li Ying <li...@gmail.com>
> wrote:
> >
> > > Hi hareendra :
> > >
> > > You don't need an ActionForm to capture the variables sent by client
> > > request.
> > >
> > > What you used to defined in ActionForm class, is now should be defined
> in
> > > Action class.
> > >
> > > You can read more detail information in
> > > http://struts.apache.org/2.2.1/docs/comparing-struts-1-and-2.html
> > > (section [Harvesting Input])
> > > about this issue.
> > >
> > > Hope this help you.
> > >
> > >
> > > 2010/9/27 hareendra seneviratne <ha...@gmail.com>
> > >
> > > > Hi all,
> > > >
> > > >
> > > >
> > > > I’m new to struts and getting to know it.
> > > >
> > > >
> > > >
> > > > Is it mandatory to have an ActionForm? Can we access the variables
> > > defined
> > > > in *view* from *execute()* method without using an ActionForm?
> > > >
> > > >
> > > >
> > > > Thnks for ur replies J
> > > >
> > >
> >
>
Re: Accessing User input in execute ( ) method
Posted by Kushan Jayathilake <ku...@gmail.com>.
yeah lol...
--
Regards
Kushan Jayathilake
On Mon, Sep 27, 2010 at 6:21 PM, Dave Newton <da...@gmail.com> wrote:
> We're all making an assumption the OP is talking about Struts 2; I made an
> assumption the opposite way.
>
> Let's just ask--Hareendra, what version of Struts are you asking about?
>
> Dave
>
> On Mon, Sep 27, 2010 at 8:45 AM, Li Ying <li...@gmail.com> wrote:
>
> > Hi hareendra :
> >
> > You don't need an ActionForm to capture the variables sent by client
> > request.
> >
> > What you used to defined in ActionForm class, is now should be defined in
> > Action class.
> >
> > You can read more detail information in
> > http://struts.apache.org/2.2.1/docs/comparing-struts-1-and-2.html
> > (section [Harvesting Input])
> > about this issue.
> >
> > Hope this help you.
> >
> >
> > 2010/9/27 hareendra seneviratne <ha...@gmail.com>
> >
> > > Hi all,
> > >
> > >
> > >
> > > I’m new to struts and getting to know it.
> > >
> > >
> > >
> > > Is it mandatory to have an ActionForm? Can we access the variables
> > defined
> > > in *view* from *execute()* method without using an ActionForm?
> > >
> > >
> > >
> > > Thnks for ur replies J
> > >
> >
>
Re: Accessing User input in execute ( ) method
Posted by Dave Newton <da...@gmail.com>.
We're all making an assumption the OP is talking about Struts 2; I made an
assumption the opposite way.
Let's just ask--Hareendra, what version of Struts are you asking about?
Dave
On Mon, Sep 27, 2010 at 8:45 AM, Li Ying <li...@gmail.com> wrote:
> Hi hareendra :
>
> You don't need an ActionForm to capture the variables sent by client
> request.
>
> What you used to defined in ActionForm class, is now should be defined in
> Action class.
>
> You can read more detail information in
> http://struts.apache.org/2.2.1/docs/comparing-struts-1-and-2.html
> (section [Harvesting Input])
> about this issue.
>
> Hope this help you.
>
>
> 2010/9/27 hareendra seneviratne <ha...@gmail.com>
>
> > Hi all,
> >
> >
> >
> > I’m new to struts and getting to know it.
> >
> >
> >
> > Is it mandatory to have an ActionForm? Can we access the variables
> defined
> > in *view* from *execute()* method without using an ActionForm?
> >
> >
> >
> > Thnks for ur replies J
> >
>
Re: Accessing User input in execute ( ) method
Posted by Li Ying <li...@gmail.com>.
Hi hareendra :
You don't need an ActionForm to capture the variables sent by client
request.
What you used to defined in ActionForm class, is now should be defined in
Action class.
You can read more detail information in
http://struts.apache.org/2.2.1/docs/comparing-struts-1-and-2.html
(section [Harvesting Input])
about this issue.
Hope this help you.
2010/9/27 hareendra seneviratne <ha...@gmail.com>
> Hi all,
>
>
>
> I’m new to struts and getting to know it.
>
>
>
> Is it mandatory to have an ActionForm? Can we access the variables defined
> in *view* from *execute()* method without using an ActionForm?
>
>
>
> Thnks for ur replies J
>
Re: Accessing User input in execute ( ) method
Posted by Kushan Jayathilake <ku...@gmail.com>.
Hi,
There is a new interface called *ActionSupport *in struts 2 you can it from
that, you just need to put
*<s:form action="summary" id="main_form" name="main_form" >* in JSP.
remember to map the action with the struts.xml. thats all you need
ie:
*<action name="summary" class="com.utc.pw.prdg.actions.PartsSearchAction"
method="performSearch">
<result name="success">/pages/ext/summary.jsp</result>
</action>*
--
Regards
Kushan Jayathilake
On Mon, Sep 27, 2010 at 4:54 PM, hareendra seneviratne <hareendras@gmail.com
> wrote:
> Hi all,
>
>
>
> I’m new to struts and getting to know it.
>
>
>
> Is it mandatory to have an ActionForm? Can we access the variables defined
> in *view* from *execute()* method without using an ActionForm?
>
>
>
> Thnks for ur replies J
>
Re: Accessing User input in execute ( ) method
Posted by Dave Newton <da...@gmail.com>.
You could get it directly from the request... but why would you want to?
That would defeat one of the purposes of having Struts, wouldn't it?
Dave
On Mon, Sep 27, 2010 at 7:24 AM, hareendra seneviratne <hareendras@gmail.com
> wrote:
> Hi all,
>
>
>
> I’m new to struts and getting to know it.
>
>
>
> Is it mandatory to have an ActionForm? Can we access the variables defined
> in *view* from *execute()* method without using an ActionForm?
>
>
>
> Thnks for ur replies J
>