Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / March 2008

Tip: Looking for answers? Try searching our database.

Persistant Class Variables In Web Application

Thread view: 
RFleming@nationalsteel.com - 27 Mar 2008 21:11 GMT
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
CK - 27 Mar 2008 21:20 GMT
>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
[quoted text clipped - 3 lines]
>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 <clauskick@mpsahotmail.com>
=(UDIC)=
d++ e++ T--
K1!2!3!456!7!S a29
"Coffee is a mocker. So, I am going to mock."

- Me, lately.
RFleming@nationalsteel.com - 27 Mar 2008 21:39 GMT
> Words to the wise, RFlem...@nationalsteel.com 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
Lew - 28 Mar 2008 07:50 GMT
CK wrote:
>> Did you try instance variables?

> 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.

Signature

Lew



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.