Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

popup from backend?

 
Tina Desai
Ranch Hand
Posts: 365
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Friends!

I have one SessionBindingListener implemented.

When the valueUnbound method is called for the object on timeout, I first want to give a popup to the user asking if he wants to save a particular data.

1. Im not sure how to send the control back to the UI and to give user a popup from java? Need help on this. Im out of any clues..
2. if he chooses to save the information, will the timeout wait till the processing is done?
The processing will involve use of httpsession and backend update call too. So I was thinking may be it should be an "inactivity" due to which actually the timeout gets kicked off. Any comments?

Regards,
Tina
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HTTP is a stateless protocol.
Servlets and JSPs can only respond to an HTTP request. Immediately after doing so the connection between the user's browser and the server is closed.

This means that events on the server have no way triggering anything on the client's machine. When your unbounded event fires, the server has no way of even knowing if the user's browser is even open, let alone still looking at your site.
 
Sunil Vasudevan
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One dirty way of doing it is to keep a track of the time left before the session expires on the client end using a timer implemented in JavaScript (use setTimeout()).

Say 30 seconds before the session is supposed to time out (specified under your web-xml), your javascript can show a pop-up informing the user the session will expire.

This is not a good way of doing it.. But if your functionality demands it, you can...
[ April 18, 2007: Message edited by: Sunil Vasudevan ]
 
Rahul Bhattacharjee
Ranch Hand
Posts: 2308
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Sunil Vasudevan:
One dirty way of doing it is to keep a track of the time left before the session expires on the client end using a timer implemented in JavaScript (use setTimeout()).

Say 30 seconds before the session is supposed to time out (specified under your web-xml), your javascript can show a pop-up informing the user the session will expire.

This is not a good way of doing it.. But if your functionality demands it, you can...

[ April 18, 2007: Message edited by: Sunil Vasudevan ]


Sunil , will this really work ?

#1 : Each time the timeout value you changes in the web.xml you have to changes the javascript.

#2 : On what event would you be calling the javascript?

#3 : The session object is in the server.Timeout specify the maximum interval on inactivity after which the session can be invalidated and session is not thread safe , other requests can be working on the same session.
 
Sunil Vasudevan
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Rahul Bhattacharjee:


Sunil , will this really work ?

#1 : Each time the timeout value you changes in the web.xml you have to changes the javascript.

#2 : On what event would you be calling the javascript?

#3 : The session object is in the server. Timeout specify the maximum interval on inactivity after which the session can be invalidated and session is not thread safe , other requests can be working on the same session.



1. Well yes, everytime I change the web.xml, I will have to change the javascript.

2. You invoke the timer with onload().

3. The session object is in server and can be accessed by other requests from the "same" client. And that would happen only if you open a new browser from the existing browser window using a CRTL+N. In this case the session ID is shared by both request. But other than that, if I start a new browser window, the same session object will not be shared. So technically what you are saying is possible, but that would happen only if the user tries to open a new browser from within an existing browser with an active session.

And well, I did mention it is a dirty solution. Don't expect the client and the server will be completely in synch.

On further thoughts, we can look at using AJAX. That should provide a cleaner solution.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64851
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Sunil Vasudevan:
On further thoughts, we can look at using AJAX. That should provide a cleaner solution.


How are you figuring that?
 
Sunil Vasudevan
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I need to check if an AJAX request maintains the same session request.

If yes, we can poll a servlet asynchronously and check last when the session was accessed using session.getLastAccessedTime() on the server end.

Using that, we can compute the actual time remaining for the session to expire. That will be available through the response. Handle a pop-up or a display based on what value is returned back.

Again, the polling needs to be done by a timer implemented using JavaScript. But now, the client side JavaScript will have the updated value for the time remaining for session to timeout.

Please let me know if you see an issue with this approach. Cause this is on theory. I haven't done a proof of concept on this.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Sunil Vasudevan:

Please let me know if you see an issue with this approach.


Any request from that browser (AJAX or otherwise) will reset the timeout of the session causing it never to expire.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64851
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Exactly. An AJax request is just like any other request as far as the server is concerned.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic