让JS以相同的形式将它们设置为隐藏的输入值。
<h:form id="formId"> <h:inputHidden id="x" value="#{bean.x}" /> <h:inputHidden id="y" value="#{bean.y}" /> <h:commandButton value="submit" onclick="getVars()" action="#{bean.submit}" /></h:form>function getVars() { // ... var x = locationInfo.lng; var y = locationInfo.lat; document.getElementById("formId:x").value = x; document.getElementById("formId:y").value = y;}命令按钮操作方法可以按通常方式将它们作为bean属性进行访问。
private int x;private int y;public void submit() { System.out.println("x: " + x); System.out.println("y: " + y); // ...}// Getters+setters.


