Tips on configuring timezone for a fusion web application
Update:
#{adfFacesContext.timeZone.ID} does not bring the browser timezone any more(this has been turned off in Trinidad layer sometime back and it will display time zone of the underlying JRE instead). this is because there are no fool proof mechanism available to identity the timezone settings for the client browser. The below blog post is no longer valid if the requirement is to read timezone set for the end-user machine/browser.
You can set the timezone for a fusion web application using the time-zone element in trinidad-config.xml
Doc says:
Apache Trinidad will attempt to default the time zone to the time zone used by the client browser. If needed, you can use an EL expression that evaluates to a TimeZone object. This value is used by org.apache.myfaces.trinidad.converter.DateTimeConverter while converting strings to Date.
Please note that the above configuration is valid only for the view layer. ADF BC layer would use the time zone configured in the adf-config.xml. And this value can be retrieved by using oracle.jbo.common.DefLocaleContext.
e.g: DefLocaleContext.getInstance().getUserTimeZone();
How to make these two layers to work on same 'timezone' ?
Yes, you can do that using EL for configuring timezone in adf-config.xml. Please see the EL #{adfFacesContext.timeZone.ID} used in the following configuration. This refers the timezone used by the view layer.
#{adfFacesContext.timeZone.ID} => AdfFacesContext.getCurrentInstance().getTimeZone().getID();
In effect, this expression help us to pass the timezone from the view layer to the business service layer in a smart way.
#{adfFacesContext.timeZone.ID} does not bring the browser timezone any more(this has been turned off in Trinidad layer sometime back and it will display time zone of the underlying JRE instead). this is because there are no fool proof mechanism available to identity the timezone settings for the client browser. The below blog post is no longer valid if the requirement is to read timezone set for the end-user machine/browser.
You can set the timezone for a fusion web application using the time-zone element in trinidad-config.xml
Doc says:
Apache Trinidad will attempt to default the time zone to the time zone used by the client browser. If needed, you can use an EL expression that evaluates to a TimeZone object. This value is used by org.apache.myfaces.trinidad.converter.DateTimeConverter while converting strings to Date.
Please note that the above configuration is valid only for the view layer. ADF BC layer would use the time zone configured in the adf-config.xml. And this value can be retrieved by using oracle.jbo.common.DefLocaleContext.
e.g: DefLocaleContext.getInstance().getUserTimeZone();
How to make these two layers to work on same 'timezone' ?
Yes, you can do that using EL for configuring timezone in adf-config.xml. Please see the EL #{adfFacesContext.timeZone.ID} used in the following configuration. This refers the timezone used by the view layer.
#{adfFacesContext.timeZone.ID} => AdfFacesContext.getCurrentInstance().getTimeZone().getID();
In effect, this expression help us to pass the timezone from the view layer to the business service layer in a smart way.
<?xml version="1.0" encoding="windows-1252" ?>
<adf-config xmlns="http://xmlns.oracle.com/adf/config"
......
<user-timezone-config xmlns="http://xmlns.oracle.com/adf/usertimezone/config">
<user-timezone expression="#{adfFacesContext.timeZone.ID}"/>
</user-timezone-config>
I think this gives server timezone always. I configured adf-config.xml with above code.
ReplyDeleteSorry, I can see this working in my sample. Please pass me a test case if you have any, will follow it up
ReplyDelete#{adfFacesContext.timeZone.ID} expression always evaluates to server timezone right? Do we need to capture the client timezone through a javascript function and pass that value to the expression below?
ReplyDelete<user-timezone expression=
#{adfFacesContext.timeZone.ID} does not bring the browser timezone any more(this has been turned off in Trinidad layer sometime back and it will display time zone of the underlying JRE instead). this is because there are no fool proof mechanism available to identity the timezone settings for the client browser.
ReplyDeleteHello,
ReplyDeleteHow to display the user login time using browser's timezone in adf?
Hi Jobinesh,
ReplyDeleteI am a bit new to ADF.
Could you please tell me what is the correct location path to this adf-config.xml. I tried to search in my existing view and there were many adf-config.xml that were existing.