You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by John Hunt <te...@yahoo.com> on 2001/01/29 05:12:09 UTC

ActionForm in this case

Hi
Consider a scenario where there is a user profile.
When a user clicks on a link to display the profile we
would get his details and would display them in
editable input fields  ( text boxes, radio buttons etc
). When he edits them and asks to save we save them.
Suppose I wish to use the same action class for both
the activities. Suppose I associate a AcitonForm for
the page. When the user clicks on the link the form
class is null ( or is it created with its attributes
null ??? ). In the action class I retrieve the
elements and populate the ActionForm using setX ( can
I actually do this ?? ). Then I put it back in the
request ( How do I do this ??? ). Then in the jsp I
use <form:text name="FirstName" value=(????what should
go here> />... Now when the user edits the fields I
can save them. ( this part is straight forward ). So
my question boils down to : When there is no form bean
associated with a request ( say a get method ), can we
create a form bean and put it in the request so that
the jsp can render it using the form ( or the latest
html ) tags?????
Thanks
Hunt

__________________________________________________
Do You Yahoo!?
Yahoo! Auctions - Buy the things you want at great prices. 
http://auctions.yahoo.com/

Re: ActionForm in this case

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

> Hi Hunt
> Sorry for the late response but i just managed doing something very
> similar..
>
> its quite easy to do and can be comfortably accomplished using struts..
>
> The link which leads to ur edit page will have the action mapping and
> also a requestParameter to identify the operation that needs to be
> performed..
>
> eg myActionClass.do?perform="populate"
>

The Struts example application does something similar to this -- the only
difference is that I chose to use two different actions (/editSubscription.do
versus /saveSubscription.do) for the two distinct functions of populating the
form bean versus saving the results to the database.

Craig McClanahan



Re: ActionForm in this case

Posted by Anand Raman <an...@mymailbag.com>.
Hi Hunt
Sorry for the late response but i just managed doing something very
similar..

its quite easy to do and can be comfortably accomplished using struts..

The link which leads to ur edit page will have the action mapping and
also a requestParameter to identify the operation that needs to be
performed..


eg myActionClass.do?perform="populate"

Corresponding to the perform request parameter u can then populate the
bean from the database, set the perform parameter to something more
appripriate like "update" and forward it to the jsp file which renders it 
in text boxes and other form elements.. 

Now when the form submits again to the same action class it will have
the perform request parameter set to "update" .. U can code appropriatly
in the action class to retrieve values from the bean and insert them
into the database..

I dont think that u will be in need for a session scope bean in this
case. It can be very well managed using a request scope bean.. However
ur requirements can differ..

The explanation i gave out here looks to be very dry. Let me know if u
have any problems. I will mail u the piece of code which i developed.. 

Hope this helps
Anand


On Sun, Jan 28, 2001 at 08:12:09PM -0800, John Hunt wrote:
>Hi
>Consider a scenario where there is a user profile.
>When a user clicks on a link to display the profile we
>would get his details and would display them in
>editable input fields  ( text boxes, radio buttons etc
>). When he edits them and asks to save we save them.
>Suppose I wish to use the same action class for both
>the activities. Suppose I associate a AcitonForm for
>the page. When the user clicks on the link the form
>class is null ( or is it created with its attributes
>null ??? ). In the action class I retrieve the
>elements and populate the ActionForm using setX ( can
>I actually do this ?? ). Then I put it back in the
>request ( How do I do this ??? ). Then in the jsp I
>use <form:text name="FirstName" value=(????what should
>go here> />... Now when the user edits the fields I
>can save them. ( this part is straight forward ). So
>my question boils down to : When there is no form bean
>associated with a request ( say a get method ), can we
>create a form bean and put it in the request so that
>the jsp can render it using the form ( or the latest
>html ) tags?????
>Thanks
>Hunt
>
>__________________________________________________
>Do You Yahoo!?
>Yahoo! Auctions - Buy the things you want at great prices. 
>http://auctions.yahoo.com/

RE: ActionForm in this case

Posted by Daniel Ostermeier <da...@cortexebusiness.com.au>.
Just a couple of pointers I can offer here..

I am assuming that for the user to be able to edit there
profile, they have been "identified" in some manor, and 
therefore this information can be stored within the session
object. This is where the default information for the form
can be retrieved. Maybe creating/initializing the bean storing 
the profile info used by the form can be done at the login
stage.

I defer the example based details to the more experienced
members of this group :)

> Consider a scenario where there is a user profile.
> When a user clicks on a link to display the profile we
> would get his details and would display them in
> editable input fields  ( text boxes, radio buttons etc
> ). When he edits them and asks to save we save them.
> Suppose I wish to use the same action class for both
> the activities. Suppose I associate a AcitonForm for
> the page. When the user clicks on the link the form
> class is null ( or is it created with its attributes
> null ??? ). In the action class I retrieve the
> elements and populate the ActionForm using setX ( can
> I actually do this ?? ). 


Daniel