I need to send a JS variable to my ManagedBean and use it in a function in my ManagedBean, i'm using JSF2 and PrimeFaces 6.
Code Js & .Xhtml:
<script type="text/javascript">
timezone = jstz.determine();
var myLocalZone =timezone.name(); // myLocalZone = "Europe/Paris"
</script>
<p:column headerText="blabla" width="125">
<h:outputText value="#{myBean.date}">
<f:convertDateTime type="both" timeZone="#{myBean.TimeZone}"> </f:convertDateTime>
</h:outputText>
ManagedBean
public void getCurrentTimezoneOffset() {
TimeZone tz = TimeZone.getTimeZone("I need To Use My Js variable Here");
Calendar cal = GregorianCalendar.getInstance(tz);
int offsetInMillis = (tz.getOffset(cal.getTimeInMillis()) * 2);
String offset = String.format("%02d", Math.abs(offsetInMillis / 3600000));
offset = (offsetInMillis >= 0 ? "+" : "-") + offset;
TimeZone = "GMT" + offset;
}
EDIT :
I tried RemoteCommand but i don't know why can't work for me !!
function customfunction() {
increment([{name:'x', value:10}, {name:'y', value:20}]);
}
</script>
I don't know where i should make the remoteCommand so i added it in the first line of my Form !
<p:remoteCommand name="increment" actionListener="#{MyBean.increment}"/>
in my Bean i have :
public void increment() {
Map<String, String> params = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap();
String x = params.get("x");
String y = params.get("y");
System.out.println("X " + x + " Y " + y);
}
NB : I need just to refresh my page and Get The x and y in my Beans..
If You have a Solution or a suggestions to solve this problem. Thanks