I am trying to get coordinates from leaflet map ( javascript) and passing them to my managed bean. In order to send javascript variable to my managed bean, I used the answer here
here is the code I'm using the JSF :
<h:form id="formId">
<h:inputHidden id="x" value="#{mapbean.latt}" />
<h:inputHidden id="y" value="#{mapbean.longt}" />
<p:remoteCommand name="myRemote" action="#{mapbean.displayLatLong()}" immediate="true" />
</h:form>
<script type="text/javascript">
function onClick(e) {
var ff = e.latlng.lat;
ff2= e.latlng.lng;
document.getElementById("formId:x").value = ff;
document.getElementById("formId:y").value = ff2;
myRemote();
}
</script>
The bean :
//....
public int latt;
public int longt;
public void displayLatLong(){
System.out.println("x: " + latt);
System.out.println("y: " + longt);
}
//getters and setters
I'm not getting errors, but the value of latt and longt are always 0. ps :latt and longt are coordinates of a marker ( leaflet marker) Edit : as Holger said in his comment, the form was not submitted,so modifying the remoteCommand solved my problem. here are the modifications :
<p:remoteCommand name="myRemote" process="@form" actionListener="#{mapbean.displayLatLong()}" />