[英]Get the returned value of Java Script to server side
我正在提高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>
你必須從JS傳遞的一些方法來支持bean,所有丑陋的我很害怕,但都在這個描述以及職位
總結一下我最常使用的方式(盡管我確實盡力設計以使我永遠不需要它),在帖子中的描述如下
<h:form id="formId">
<h:inputText id="inputId" value="#{bean.property}" />
<h:commandButton id="buttonId" value="Button" action="#{bean.action}" />
</h:form>
因此是JSF表單(通常不可見)和js代碼
<script type="text/javascript">
document.getElementById('formId:inputId').value = 'foo';
document.getElementById('formId:buttonId').click();
// Or: document.getElementById('formId').submit();
</script>
因此,如果您無法避免這種情況,請傳遞值並定位您的bean,您將獲得解決方案
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.