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/09/21 15:00:00 UTC

Scope of form beans

Hi,

I'm a bit confused... so I hope this makes some sense.

I wish to display a form for the user to edit. BUT the form isn't empty 
it needs to come from a bean that is sitting in an ArrayList. Is there 
some way to do this directly?

My answer (that doesn't work) is to create a "standalone" bean (of 
the same type) in the action form that forwards to the page. I've tried 
this a number of different ways but my form does not see the bean 
"bean not found etc". I am creating the bean in request scope - is 
this correct?

Without ranting on any more, what are the "rules" for doing this, 
assuming its a good idea at all.

Howard

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Scope of form beans

Posted by kiuma <ki...@usa.net>.
1) save the array list in the http session.
2) don't call jsp, but call the action related to it.
3) Pick your data from ArrayList
4) Cast the variable form in execute method ( or equvalent ) to the 
related form
5) Fill that form with the data jet picked.

You'll display the data.




Howard Miller wrote:

>Hi,
>
>I'm a bit confused... so I hope this makes some sense.
>
>I wish to display a form for the user to edit. BUT the form isn't empty 
>it needs to come from a bean that is sitting in an ArrayList. Is there 
>some way to do this directly?
>
>My answer (that doesn't work) is to create a "standalone" bean (of 
>the same type) in the action form that forwards to the page. I've tried 
>this a number of different ways but my form does not see the bean 
>"bean not found etc". I am creating the bean in request scope - is 
>this correct?
>
>Without ranting on any more, what are the "rules" for doing this, 
>assuming its a good idea at all.
>
>Howard
>
>--
>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: I do not understand html:link with action

Posted by Eddie Bush <ek...@swbell.net>.
Did you examine the example application at all? :-)

I belive what you're looking for is the "name=" attribute of the link tag.

You should actually look over some of the sample applications :-)  They 
didn't write them just to make the download slower ;-)

Ralf E. Stranzenbach wrote:

>Hi,
>
>i tried to use the "html:link" tag with some action parameter within my
>navigation screen. But i can't find the right notation to reference one of
>my ActionMappings from the struts-config.xml. I've read the documentation
>but i have no idea what's wrong with it.
>
>Please enlight me!
>
>I have a second question - is there some good example on how to use multiple
>sub-applications with struts-1.1 ?
>
>Many thanks,
>Ralf E. Stranzenbach
>

-- 
Eddie Bush




--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


I do not understand html:link with action

Posted by "Ralf E. Stranzenbach" <mo...@reswi.de>.
Hi,

i tried to use the "html:link" tag with some action parameter within my
navigation screen. But i can't find the right notation to reference one of
my ActionMappings from the struts-config.xml. I've read the documentation
but i have no idea what's wrong with it.

Please enlight me!

I have a second question - is there some good example on how to use multiple
sub-applications with struts-1.1 ?

Many thanks,
Ralf E. Stranzenbach



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: Scope of form beans

Posted by Robert Taylor <rt...@mulework.com>.
Howard, there are a couple different ways to achieve the results you desire.
I'll explain one that is the "path of least resistance".

Screen 1: Displaying the list

You already say you have a bean in session scope which contains your list.
So, to display the list all you should really have to do is either forward
(via an action ) to the .jsp page that displays your list or call the .jsp
directly. On the page that displays your list, you can use the logic:iterate
tag to render your list to the screen. (I'm assuming you've already
successfully rendered the bean, if not let me know).
You say that each item has an "edit button" next to it. For now, I'll assume
that this edit button is
a hyperlinked image button that when clicked will send a request to a
"showEditItemAction" with some information in the query string which
uniquely identifies the item which you wish to edit.


Screen 2: Displaying the item to be edited

As mentioned above the user has selected an item from the list by clicking
the appropriate edit button. The button is a hyperlinked button which sends
a request to an action that will prepare the edit page for display; let's
call the action "showEditItemAction". ShowEditItemAction  retrieves the
query string parameter which uniquely identifies the item in the bean.
ShowEditItemAction gets the identified item from the bean and populates the
ActionForm and then forwards to screen 2 which will render the contents of
the form.


Now, the best way to do this is subjective and relative to your requirements
and existing architecture.
This sounds like a classic master-detail problem in which you display a
master list of items to select from and when the user selects an item, it's
details are displayed on another screen (either for edit or display). You
can search the archives for master-detail and probably find a lot of
solutions that are similar.

Eddie has already alluded to a popular approach where you have an action
which prepares the master list screen for display; an action which prepares
the detail screen for display; and finally an action which saves any changes
and forwards back to the list.


Let me know if you need more clarification.

robert


> -----Original Message-----
> From: Howard Miller [mailto:me@howardmiller.co.uk]
> Sent: Saturday, September 21, 2002 2:27 PM
> To: Struts Users Mailing List
> Subject: Re: Scope of form beans
>
>
> Errr..
>
> may I take a step back, and explain what I want to do, rather that
> how I'm doing it wrong!
>
> - I have a bean in the session scope (working fine).
> - This session bean has an ArrayList 'pointing to' a number of other
> beans.
> - Screen 1: The array list is displayed for the user, with an edit button
> next to each item. (ie, list of items, and the user can edit the content
> of each one).
> - Screen 2: The user has selected one of the ArrayList items and can
> now edit the contents.
> - After editing we go back to screen 1, to pick another if need be.
>
> What's the best way to do this, basically? Its kind of like a shopping
> cart scenario (it isn't - but just to get over the idea), so it
> should be a
> common situation
>
> Cheers.... Howard
>
> On 21 Sep 2002 at 10:32, Eddie Bush wrote:
>
> > So you're trying to pre-populate a form?  ... which you're just
> about to
> > show a user?
> >
> > link -> action f-> JSP  (f-> == forward)
> >
> > - link points to action
> > - action populates form
> > - action forwards control to JSP
> >
> > Is this your scenario?
> >
> > You need to:
> >     - build a form-bean (by extending ActionForm) or use a
> > DynaActionForm (or similar)
> >     - associate the form-bean with the action (so Struts will create it)
> >     - extend Action (or one of it's descendants) and code the "execute"
> > method so that it pre-populates your bean and then forwards to
> the JSP page.
> >
> > Once you have done this, your action is passed an instance of the
> > form-bean which should be available to the JSP page.  You just populate
> > it and forward control.  Be aware though :-) that if you  then send the
> > user to a "view" page (to show what their edits were, perhaps), you'll
> > have to be looking in the same scope for the form-bean, or you're not
> > gonna find it ;-)
> >
> > Ex:
> >
> > <action path="/editUser" ... scope="request" ... />
> > <action path="/viewUser" ... scope="request" ... />
> >
> > The default scope is session.  If that's where you want the form kept
> > you don't have to specify it.
> >
> > Howard Miller wrote:
> >
> > >Hi,
> > >
> > >I'm a bit confused... so I hope this makes some sense.
> > >
> > >I wish to display a form for the user to edit. BUT the form
> isn't empty
> > >it needs to come from a bean that is sitting in an ArrayList. Is there
> > >some way to do this directly?
> > >
> > >My answer (that doesn't work) is to create a "standalone" bean (of
> > >the same type) in the action form that forwards to the page.
> I've tried
> > >this a number of different ways but my form does not see the bean
> > >"bean not found etc". I am creating the bean in request scope - is
> > >this correct?
> > >
> > >Without ranting on any more, what are the "rules" for doing this,
> > >assuming its a good idea at all.
> > >
> > >Howard
> > >
> > >--
> > >To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
> >For additional commands, e-mail:
<ma...@jakarta.apache.org>
> >
>
> --
> 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>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Scope of form beans

Posted by Howard Miller <me...@howardmiller.co.uk>.
Errr..

may I take a step back, and explain what I want to do, rather that 
how I'm doing it wrong!

- I have a bean in the session scope (working fine).
- This session bean has an ArrayList 'pointing to' a number of other 
beans.
- Screen 1: The array list is displayed for the user, with an edit button 
next to each item. (ie, list of items, and the user can edit the content 
of each one).
- Screen 2: The user has selected one of the ArrayList items and can 
now edit the contents.
- After editing we go back to screen 1, to pick another if need be.

What's the best way to do this, basically? Its kind of like a shopping 
cart scenario (it isn't - but just to get over the idea), so it should be a 
common situation

Cheers.... Howard

On 21 Sep 2002 at 10:32, Eddie Bush wrote:

> So you're trying to pre-populate a form?  ... which you're just about to 
> show a user?
> 
> link -> action f-> JSP  (f-> == forward)
> 
> - link points to action
> - action populates form
> - action forwards control to JSP
> 
> Is this your scenario?
> 
> You need to:
>     - build a form-bean (by extending ActionForm) or use a 
> DynaActionForm (or similar)
>     - associate the form-bean with the action (so Struts will create it)
>     - extend Action (or one of it's descendants) and code the "execute" 
> method so that it pre-populates your bean and then forwards to the JSP page.
> 
> Once you have done this, your action is passed an instance of the 
> form-bean which should be available to the JSP page.  You just populate 
> it and forward control.  Be aware though :-) that if you  then send the 
> user to a "view" page (to show what their edits were, perhaps), you'll 
> have to be looking in the same scope for the form-bean, or you're not 
> gonna find it ;-)
> 
> Ex:
> 
> <action path="/editUser" ... scope="request" ... />
> <action path="/viewUser" ... scope="request" ... />
> 
> The default scope is session.  If that's where you want the form kept 
> you don't have to specify it.
> 
> Howard Miller wrote:
> 
> >Hi,
> >
> >I'm a bit confused... so I hope this makes some sense.
> >
> >I wish to display a form for the user to edit. BUT the form isn't empty 
> >it needs to come from a bean that is sitting in an ArrayList. Is there 
> >some way to do this directly?
> >
> >My answer (that doesn't work) is to create a "standalone" bean (of 
> >the same type) in the action form that forwards to the page. I've tried 
> >this a number of different ways but my form does not see the bean 
> >"bean not found etc". I am creating the bean in request scope - is 
> >this correct?
> >
> >Without ranting on any more, what are the "rules" for doing this, 
> >assuming its a good idea at all.
> >
> >Howard
> >
> >--
> >To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> >For additional commands, e-mail: <ma...@jakarta.apache.org>
> >
> 
> -- 
> 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: Scope of form beans

Posted by Eddie Bush <ek...@swbell.net>.
So you're trying to pre-populate a form?  ... which you're just about to 
show a user?

link -> action f-> JSP  (f-> == forward)

- link points to action
- action populates form
- action forwards control to JSP

Is this your scenario?

You need to:
    - build a form-bean (by extending ActionForm) or use a 
DynaActionForm (or similar)
    - associate the form-bean with the action (so Struts will create it)
    - extend Action (or one of it's descendants) and code the "execute" 
method so that it pre-populates your bean and then forwards to the JSP page.

Once you have done this, your action is passed an instance of the 
form-bean which should be available to the JSP page.  You just populate 
it and forward control.  Be aware though :-) that if you  then send the 
user to a "view" page (to show what their edits were, perhaps), you'll 
have to be looking in the same scope for the form-bean, or you're not 
gonna find it ;-)

Ex:

<action path="/editUser" ... scope="request" ... />
<action path="/viewUser" ... scope="request" ... />

The default scope is session.  If that's where you want the form kept 
you don't have to specify it.

Howard Miller wrote:

>Hi,
>
>I'm a bit confused... so I hope this makes some sense.
>
>I wish to display a form for the user to edit. BUT the form isn't empty 
>it needs to come from a bean that is sitting in an ArrayList. Is there 
>some way to do this directly?
>
>My answer (that doesn't work) is to create a "standalone" bean (of 
>the same type) in the action form that forwards to the page. I've tried 
>this a number of different ways but my form does not see the bean 
>"bean not found etc". I am creating the bean in request scope - is 
>this correct?
>
>Without ranting on any more, what are the "rules" for doing this, 
>assuming its a good idea at all.
>
>Howard
>
>--
>To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
>For additional commands, e-mail: <ma...@jakarta.apache.org>
>

-- 
Eddie Bush




--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>