【发布时间】:2017-10-07 12:08:36
【问题描述】:
我正在尝试从传单地图 (javascript) 中获取坐标并将它们传递给我的托管 bean。为了将 javascript 变量发送到我的托管 bean,我使用了答案 here
这是我正在使用的代码 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>
豆子:
//....
public int latt;
public int longt;
public void displayLatLong(){
System.out.println("x: " + latt);
System.out.println("y: " + longt);
}
//getters and setters
我没有收到错误,但 latt 和 longt 的值始终为 0。 ps :latt 和 longt 是标记的坐标(传单标记) 编辑:正如 Holger 在他的评论中所说,表单没有提交,所以修改 remoteCommand 解决了我的问题。以下是修改:
<p:remoteCommand name="myRemote" process="@form" actionListener="#{mapbean.displayLatLong()}" />
【问题讨论】:
-
谁打电话给
onClick()? -
它是标记上的点击监听器。我通过以下命令在我的 bean 中定义它:
RequestContext.getCurrentInstance().execute("layer.on('click', onClick)");onClick 正在工作,我通过显示警报对其进行了测试(添加了这行代码到点击:alert(" lat/long : " + x+","+y); -
如果调用生成 POST 请求,您应该查看浏览器控制台。我不这么认为,因为您调用 remoteCommand 并且没有人提交表单。
-
是的,我认为这就是问题所在!不生成发布请求。我会尝试让我的远程命令提交表单。
标签: javascript java jsf