*
The moose likes OO, Patterns, UML and Refactoring and the fly likes Maintaining user state in a web application Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » OO, Patterns, UML and Refactoring
Bookmark "Maintaining user state in a web application" Watch "Maintaining user state in a web application" New topic
Author

Maintaining user state in a web application

Sonny Gill
Ranch Hand

Joined: Feb 02, 2002
Posts: 1211

Hi All. Looking for some war stories here on this tricky question.

Let us consider a fairly simple scenario.
We have a 'table view' JSP which displays some data that can be sorted on any column. From this page, the user can choose a record and view a detail page. The detail page contains a link back to the master page. If the user clicks the link, when the master 'table view' page is displayed, it should have the data sorted in the same order as when the user moved out from that page.

The possible ways to do it that I can think of would be -

1. Store the user selection (on the ordering) in HTTP session, or
2. Use URL rewriting to include that information, or
3. Use hidden form fields.

The 1st option leaves us with the problem of deciding when to clear the session. Either the 2nd or the 3rd will work, but it starts to get really complex, if the records in the master 'table view' page have child records with their own 'table view' and detail pages, all with links back to the parent 'table view' page.

Any ideas on how to handle it in a clean intuitive way will be much appreciated? Could
Spring WebFlow be any help in this case?
[ June 06, 2005: Message edited by: Sonny Gill ]

The future is here. It's just not evenly distributed yet. - William Gibson
Consultant @ Xebia. Sonny Gill Tweets
Andrew Nomos
Greenhorn

Joined: May 31, 2005
Posts: 18
You could store a HashMap in HTTP session with the name of the JSP as key and the name of the column as value.

----------------------------

The box said: Install Windows 98 or better. So I installed linux.
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
Here are some places you can store state from my Internet Architectures page:

And I forgot all about the browser: JavaScript objects on a top level window shared by frames or iframes. The linked page has a little more on pros & cons of each.


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Sonny Gill
Ranch Hand

Joined: Feb 02, 2002
Posts: 1211

Originally posted by Andrew Nomos:
You could store a HashMap in HTTP session with the name of the JSP as key and the name of the column as value.



Hi Andrew. That leaves us with the issue of when to clear that HashMap from the memory (or the values in it). In a large site (100's of JSPs) with many clients connecting in, and possibly staying connected for hours at a time, this can be a very real problem.
Sonny Gill
Ranch Hand

Joined: Feb 02, 2002
Posts: 1211

Originally posted by Stan James:

[/QB]


Thanks Stan.
I want to avoid JavaScript/cookies for this if I can.
Option 5 is something I had not thought about before. Could you point me to some resources on that?

Right now I am considering have each controller/manager define the keys which it looks for in the request parameters to decide the latest user selected preference. The keys have to be globally unique, something like module1.submodule1.sortColumn. And maintain these between requests using hidden form fields or URL rewriting.

I want to minimize the complexity in 'remembering' the user preferences for the parent records when the user is browsing the child records 2 or 3 levels deep.

Cheers.
Sathvathsan Sampath
Ranch Hand

Joined: Oct 03, 2000
Posts: 96
by Sonny Gill
Hi Andrew. That leaves us with the issue of when to clear that HashMap from the memory (or the values in it). In a large site (100's of JSPs) with many clients connecting in, and possibly staying connected for hours at a time, this can be a very real problem.


1) Do you have any notion of a workflow or wizard or a sequence of steps for the user to perform on your ui? If yes, then the start and end of the workflow might determine the life of those values in the session.

2) If sorting, paging etc occurs on the server side then having the context state values on session might make it easier to perform those operations.

3) Do you really need to store lot of values in session? Did you try profiling for potential performance issues?


- Sathvathsan Sampath
Sonny Gill
Ranch Hand

Joined: Feb 02, 2002
Posts: 1211

Hi Sathvathsan. Thanks for the reply.


1) Do you have any notion of a workflow or wizard or a sequence of steps for the user to perform on your ui? If yes, then the start and end of the workflow might determine the life of those values in the session.


Yes, there are typical workflows from the starting page, but the user can choose to not complete the steps and return to any page up in the hierarchy at any time through a menu bar that always shows where the user currently is, and provides link to all parent pages.

2) If sorting, paging etc occurs on the server side then having the context state values on session might make it easier to perform those operations.

Yes, it happens in the session, and storing the state in session does make it easier.

3) Do you really need to store lot of values in session? Did you try profiling for potential performance issues?[/QB]

I havent tried profiling for performance issues that may be caused by storing state in session yet. But, the (intranet) web application I am working on consists of close to a 1000 pages, and multiple users are expected to stay logged in for long periods of time. I think it would be better to not store the state in session if alternatives exist.
Sathvathsan Sampath
Ranch Hand

Joined: Oct 03, 2000
Posts: 96
By Sonny Gill
Yes, there are typical workflows from the starting page, but the user can choose to not complete the steps and return to any page up in the hierarchy at any time through a menu bar that always shows where the user currently is, and provides link to all parent pages.


I am guessing that you might have a lightweight workflow manager that is aware of whether the user discarded at some point in the workflow or not. Your session could have values keyed against a workflow. When he jumps out of it to another one, the workflow manager could detect this and perform some life cycle management operations.
I'd first profile to gather data on performance to prove any speculation and weigh other relevant contraints.
Sonny Gill
Ranch Hand

Joined: Feb 02, 2002
Posts: 1211

Thanks Sathvathsan. The idea of a lightweight workflow manager is interesting.
Unfortunately, working with legacy code makes some of the simple tasks very difficult. Should be fun

Cheers.
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
I have pretty limited hands-on with XML islands. It may well be an IE-only syntax on the page. We parse the XML in JavaScript and populate form fields, but I guess you would want to just post it back to the server.

My current project went right for the more expensive options - write everything through to a database. It handles clustering and load balancing better than something in server memory, and even survives server failure so users can come back later and pick up where they left off. It may turn out you have none of those requirements and this would be overkill.
Sonny Gill
Ranch Hand

Joined: Feb 02, 2002
Posts: 1211

Thanks Stan.
I have to wait to see what priority is assigned to this task, and then choose one of the options.
Cheers.
 
Consider Paul's rocket mass heater.
 
subject: Maintaining user state in a web application
 
Similar Threads
Spring Web Flow 2 Web Development
spring web flow-tiles
Enabling links according to user's authorization
Retrieving ArrayList from Display Table after sorting
In Spring Webflow Is the execution URL request parameter necessary ?