About Beenish Zaidi Expertise I can answer questions related to Core Java(no swing), Spring, to some extent i can try helping in solving problems related to JSP's and Servlets as well.
Have hands on experience on Jakarta Struts and Struts Validator framework.
Any questions within this domain are welcome.Just started with Design patterns, so any questions will be welcome in this category also.
Experience 2 and a half years.
Education/Credentials Bachelors in Computer Sciences
Expert: Beenish Zaidi Date: 7/1/2008 Subject: arraylist
Question QUESTION: i want to use arraylist of beans to store data throughout my application but i am unable to prevent arraylist from getting initialize eachtime whenever i am callig that file where i am using arraylist.
how can i initialize arraylist once and use it throughout the application??
please give me suggesions
thanks in advance.
ANSWER: Well Nidhi,
Glad to recieve your note.
One way to use this arraylist throughout your program is to
make it static and declare it at the class level. Additionally
it is hard to tell, without seeing your code, that what scenario
you are exactly facing.
Hope this helps.
Ben
---------- FOLLOW-UP ----------
QUESTION: hey thanks Ben.
actually i am developing a web application which will be used by number of user.if i use static Arraylist, it will be common across all the user which i don want.i want that Arraylist to be specific to that perticular user so that i can store the respective data till he/she is using that application.
basically problem is:
in this application user can create number of tables and detail of all the table will be converted to the XML.
so what i am doing is, as user enters the data for first table,i store it in list of bean and then again if user create another table,again i initialize that list and store the data but my problem is while i initialze the list second time, i will lose my prevous data so i am thinking that before initialzation i will store the previous data in another List but again facing the same problem as each time this list will also have to be initialsed. so is there any way where i can initialise the List once and use it through out the application.
hope you will understand my problem....
Answer Dear Nidhi,
Glad to recieve your note.
Nidhi, there are two ways to solve this particular problem
a) If you want to store the information, when user has logged
in one session. Means a user has logged in and for that particular
session, you want to store everything user is doing like for
example you are saying creating tables, storing those table
information in a bean and that bean objects must be getting
added to an arrayList. One solution can be, you use another
array list and store the information in that other list as
you are doing, and then keep that list in the session scope.
Then due to session scope this list can be accessed in different
views(jsp's) or service layer. I believe you are using struts,
but same definition holds true for other frameworks also. But
even if you don't use another list, if you keep one list only
it will serve your purpose. Check out this example, very
simple but you will understand what i am talking about
b) Now if you say, you want to store the information of the
user for multiple sessions, like user closes the browser and
comes back, then you don't have any other way, rathern then
to store this information in a DAO in some database like Oracle, Sysbase or any database you are using.