views:

220

answers:

2

Hi, How can i get the browser/client time when the page loads in portlet. I need to do an algorithm based on the clients time zone, What it means is that during the render phase of the portlet I need to get the time zone of the browser. Is it possible, if so how ?

Any Help is greatly appreciated.

Thanks, Micheal

A: 

I don't know portlet, but if it has a javascript interface, perhaps call dateObject.getTimezoneOffset()?

wallyk
i need the client time when the page loads first, not after it loads and subsequent requests
A: 

I think that an HTTP request does not include any information about the browser/client time, so you're going to need to work around that using javascript somehow. I found an article regarding this issue here.

I can think of a couple of strategies I might use, depending on the circumstances:

  1. Grab the client time with javascript on the previous portal page and include it in the request to the target page via form submission.
  2. Set the portlet view to a 'Please wait' message on the initial page load and send the client time to the server via an AJAX request. When the request returns, update the portlet view as needed. If you're writing a JSR 286 portlet, the portlet can implement the ResourceServingPortlet interface to provide a hook (i.e. serveResource method) to render markup fragments. For more information, you can download the JSR 286 spec here (Check out chapter 14 on 'Serving Fragments through Portlets').
  3. Use portlet preferences to set a default time zone for the portlet. Let users select a different time zone if they choose. This gives you complete control over the time zones you support without depending on the browser or javascript at all. Portlet preferences are described in chapter 17 of the spec mentioned in #2 above.
cc1001