I am doing JSF geolocation service where I need to pass latitude and longitude to bean for processing. HTML5 allows getting location with JavaScript, for example like is done in http://code.google.com/p/geo-location-javascript/. Putting following code to JSF page shows alert with GPS coordinates
我正在做JSF地理定位服务,我需要将经度和经度传递给bean进行处理。 HTML5允许使用JavaScript获取位置,例如http://code.google.com/p/geo-location-javascript/中所做的操作。将以下代码放入JSF页面会显示带GPS坐标的警报
<script>
if (geo_position_js.init()) {
geo_position_js.getCurrentPosition(success_callback,error_callback,{enableHighAccuracy:true,options:5000});
} else {
alert("Functionality not available");
}
function success_callback(p) {
alert('lat='+p.coords.latitude.toFixed(2)+';lon='+p.coords.longitude.toFixed(2));
}
function error_callback(p) {
alert('error='+p.message);
}
</script>
How to use p.coords.latitude.toFixed(2)
value to pass it for example to h:inputtext
component?
如何使用p.coords.latitude.toFixed(2)值将它传递给h:inputtext组件?
1 个解决方案
#1
9
You need to realize that JSF runs at webserver and produces a bunch of HTML/CSS/JS code which get sent from webserver to webbrowser and that the webbrowser only runs HTML/CSS/JS. Rightclick the page in webbrowser and choose View Source. In place of the <h:inputText>
you'll see something like
你需要意识到JSF在webserver上运行并产生一堆HTML / CSS / JS代码,这些代码从webserver发送到webbrowser,而webbrowser只运行HTML / CSS / JS。在webbrowser中右键单击该页面,然后选择“查看源”。代替
<input type="text" id="formid:inputid" />
In JS, you can easily grab HTML elements from the HTML DOM using document
functions and alter it.
在JS中,您可以使用文档函数轻松地从HTML DOM中获取HTML元素并进行更改。
var input = document.getElementById('formid:inputid');
input.value = 'new value';
See also:
- Communication between Java/JSP/JSF and JavaScript
Java / JSP / JSF和JavaScript之间的通信
#1
9
You need to realize that JSF runs at webserver and produces a bunch of HTML/CSS/JS code which get sent from webserver to webbrowser and that the webbrowser only runs HTML/CSS/JS. Rightclick the page in webbrowser and choose View Source. In place of the <h:inputText>
you'll see something like
你需要意识到JSF在webserver上运行并产生一堆HTML / CSS / JS代码,这些代码从webserver发送到webbrowser,而webbrowser只运行HTML / CSS / JS。在webbrowser中右键单击该页面,然后选择“查看源”。代替
<input type="text" id="formid:inputid" />
In JS, you can easily grab HTML elements from the HTML DOM using document
functions and alter it.
在JS中,您可以使用文档函数轻松地从HTML DOM中获取HTML元素并进行更改。
var input = document.getElementById('formid:inputid');
input.value = 'new value';
See also:
- Communication between Java/JSP/JSF and JavaScript
Java / JSP / JSF和JavaScript之间的通信