In this example, we will learn how to use RemoteCommand to execute backing bean methods from javascript.
This example also provides a way to find client's time zone offset on the JSF managed bean side. There's a standard header 'Accept-Language' which can help us to find the client's locale, but there's no standard header to get client's time zone information on the server side. Though on the client side, we can use JavaScript's Date#getTimeZoneOffset() to get that information.
JSF page
src/main/webapp/index.xhtml
<h:body style="margin-left:50px">
<h2>PrimeFaces RemoteCommand Example</h2>
<h:form>
<p:remoteCommand name="updateTz" update="tz" actionListener="#{timeZoneBean.updateClientTz}"/>
Client time zone offset:
<b>
<h:outputText id="tz" value="#{timeZoneBean.clientTzOffset}"/>
</b>
</h:form>
<script type="text/javascript">
$(document).ready(function() {
var date = new Date();
var offSetVal = date.getTimezoneOffset();
updateTz([{name:'offset',value:-offSetVal/60}]);
});
</script>
</h:body>