So let me see if I'm following you. Let's set up a hypothetical example.

Lets say you have a form bean called "EmployeeForm". On the actual JSP page you want a 
drop down select to be populated from an ArrayList of DepartmentBeans. Lets say we 
want to have deptID for the value and deptName for the label. 

Now In you EmployeForm object would you have the two fields:

private int deptID;
private ArrayList departmentsList;

Then in an action that sets up everything you'd call a setter to populate the 
departmentsList in the actual EmployeeForm object? and then whenever you need that 
depratmentList (say for a select list) you'd call it from this form object?

Thanks for the info.

-----Original Message-----
From: Marcelo Vanzin <[EMAIL PROTECTED]>
To: Struts Users Mailing List <[EMAIL PROTECTED]>
Date: Mon, 22 Apr 2002 15:04:36 -0300
Subject: Re: Where is it best to populate default form bean collections et c?

Hoang, Hai wrote:
> I've been using the Action classes to load the required data for the form
> and place it under session object if the data does change often and the
> dropdown is being used repeatedly. ...  Just be sure to remove these collections 
>from the
> session object when you are done.

        The "clean up" part is tricky, because you can't be sure of when the data 
can be cleaned up, and you can't rely on the user to click somewhere 
that'll fire an action to make that cleanup...

        Around here, because we have lots of "static" data on the pages and 
querying the remove server (EJB) for these data would be very onerous, 
we do the following:

        - All our form beans are in the session scope. This way, we populate them 
with the necessary collections and other data needed for the JSP, and we 
don't need to re-populate this data in later requests from that user.

        - No data is stored outside the form bean. Everything on the JSPs is 
loaded from the form bean.

        - On each request, we look for the objects stored in the user's session 
and, in case it is a form bean but is not the form bean of the current
request, it is deleted.

        The last part may seem "heavy" since in every request I loop through
everything in the session, but, due to the way we implemented
(everything in the bean) we generally have 2 or 3 objects in the session
(the form bean, the "Locale" object and the "token" for preventing
repeated requests from being processed).

        Also, we have some mechanisms for when we do not want a form bean to be
erased from the session (since all our forms use session scope, there
are times when we may need more than one bean in the session).

        It may not be the most beautiful thing to do, but it has been working
very well. =)

--
[]'s
Marcelo Vanzin
Touch Tecnologia
[EMAIL PROTECTED]
"Life is too short to drink cheap beer"


--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>





--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to