I want to load JavaScript function on startup with window.onload and that function would pass its parameters to a Managed Bean.
Without a commandButton.
JS:
window.onload = function getVars() {
// ...
var x = locationInfo.lng;
var y = locationInfo.lat;
document.getElementById("formId:x").value = x;
document.getElementById("formId:y").value = y;
}
XHTML:
<h:form id="formId">
<h:inputHidden id="x" value="#{bean.x}" />
<h:inputHidden id="y" value="#{bean.y}" />
</h:form>
Managed Bean is a regular managed bean with its getters and setters.
This code is not working without clicking a commandButton.
Is there way to load parameters with JavaScript and pass it to JSF?