【发布时间】:2014-12-22 05:04:22
【问题描述】:
我正在学习 JSF 的技能 我正在尝试将当前位置从 JS 获取到 JSf,然后将其传递回 FirstBean.nowLoc bean。我尝试了很多选择,但没有运气:( 谁能帮帮我?
<h:message id="errors" for="User_ID" style="color:red" />
<h:form id="getLoc">
<h3>
<h:inputHidden id="xxx" binding="#{FirstBean.nowLoc}" />
</h3>
</h:form>
<p>
<h:outputText id="c"
value="currentLocation ----- #{FirstBean.currentLocation }"/>
<h:outputText id="x" value="nowLoc-------------->#{FirstBean.nowLoc}"/>
<script>
getLocation();
function getLocation() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(showPosition);
} else {
alert("Geolocation is not supported by this browser.");
}
}
function showPosition(position) {
loc = "***Latitude: " + position.coords.latitude
+ "***Longitude: " + position.coords.longitude;
document.getElementById("getLoc:xxx").value = loc;
return loc;
}
</script>
【问题讨论】:
-
不是很清楚你在问什么。您是否在问如何将当前位置从您的网页发送回您的服务器?
-
完全正确!现在我现在得到Loc------------->javax.faces.component.html.HtmlInputHidden@623823bc 但我想看到“***Latitude:” + position.coords.latitude + "***经度:" + position.coords.longitude;当我打电话给 FirstBean.nowLoc
-
您需要使用 ajax 调用将数据发送到您的服务器。在您的服务器上创建一个端点,然后使用 ajax 调用将数据发送到该端点。
-
你有没有打电话给
getLocation()?为什么元素 ID 中有特殊字符? -
在我调用 getLocarion() 的脚本中
标签: java javascript jsp jsf