Persistant Class Variables In Web Application

R

RFleming

I am fairly new to java web applications. I am trying to port over a
regular java project and I am running into a problem I can not seem to
find a good answer to. I have a database and some combo boxes. If
you select one dropdownlist box, it builds a couple of arraylists that
are private class variables, and also builds the next dropdownlist
box. When I next press on the second dropdownlist box, the page init
gets called (why I am not sure), and apparently all the controls on
the page keep thier values, but all my class variables get wiped out.
This causes the code in my second dropdownlist box to fail because it
is expecting data to be in those class variables.

Searches on the net suggest caching, or using a bean to store data. I
have not found an answer yet that I truly feel reflects my situation,
so I am hoping someone can provide me some assistance.

I am using Netbeans 6.1, and Tomcat 6.0 for the server.

Thanks For Your Time

Ryan
 
C

CK

Words said:
I am fairly new to java web applications. I am trying to port over a
regular java project and I am running into a problem I can not seem to
find a good answer to. I have a database and some combo boxes. If
you select one dropdownlist box, it builds a couple of arraylists that
are private class variables, and also builds the next dropdownlist
box. When I next press on the second dropdownlist box, the page init
gets called (why I am not sure),

What is your code doing? Do you have some listeners defined?
and apparently all the controls on
the page keep thier values, but all my class variables get wiped out.
This causes the code in my second dropdownlist box to fail because it
is expecting data to be in those class variables.

Did you try instance variables?

Searches on the net suggest caching, or using a bean to store data. I
have not found an answer yet that I truly feel reflects my situation,
so I am hoping someone can provide me some assistance.

In the web, data is normally valid for one request. If you want more,
you either pass the data on via request params, or if you use beans,
you use SessionBeans or ApplicationBeans.
--
Claus Dragon <[email protected]>
=(UDIC)=
d++ e++ T--
K1!2!3!456!7!S a29
"Coffee is a mocker. So, I am going to mock."

- Me, lately.
 
R

RFleming

Words to the wise, (e-mail address removed) wrote:


What is your code doing? Do you have some listeners defined?

Yes, Because each dropdownlist is dynamically changed by the users
action on the previous dropdownlist, I use processValueChange
listeners using auto submit on change property. As the user chooses
an option in the first dropdown, the second one becomes visible and is
populated through a resultset, on to number three and finally
dropdownlist 4, which will populate a textbox report.

Did you try instance variables?

No, I will have to research this, first I have heard of them.

In the web, data is normally valid for one request. If you want more,
you either pass the data on via request params, or if you use beans,
you use SessionBeans or ApplicationBeans.


I was not sure if I was setting up something wrong in a property, or
if the data survining one request was normal. I will take your
information and attempt to find a good solution by either an instance
variable or a bean.


Thanks for your Reply

Ryan
 
L

Lew

No, I will have to research this, first I have heard of them.

An instance variable is simply a non-static member variable of a class. They
get their name from the fact that they are scoped to an instance of the class.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top