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 :
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();
}
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 :
解决方案
You don't need a form and all this stuff.
function onClick(e) {
myRemote([
{ name: 'latt', value: e.latlng.lat },
{ name: 'longt', value: e.latlng.lng }
]);
};
and at server side
Map params = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap();
String latt = params.get("latt");
String longt = params.get("longt");