struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Howard Miller" ...@howardmiller.co.uk>
Subject Re: Scope of form beans
Date Sat, 21 Sep 2002 18:26:55 GMT
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:   <mailto:struts-user-unsubscribe@jakarta.apache.org>
> >For additional commands, e-mail: <mailto:struts-user-help@jakarta.apache.org>
> >
> 
> -- 
> Eddie Bush
> 
> 
> 
> 
> --
> To unsubscribe, e-mail:   <mailto:struts-user-unsubscribe@jakarta.apache.org>
> For additional commands, e-mail: <mailto:struts-user-help@jakarta.apache.org>
> 
> 



--
To unsubscribe, e-mail:   <mailto:struts-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:struts-user-help@jakarta.apache.org>


Mime
View raw message