我正在做 JSF 地理定位服务,我需要将纬度和经度传递给 bean 进行处理.HTML5 允许使用 JavaScript 获取位置,例如在 http://code.google.com/p/geo-location-javascript/.将以下代码放入 JSF 页面会显示带有 GPS 坐标的警报
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
<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>
如何使用 p.coords.latitude.toFixed(2) 值将其传递给例如 h:inputtext 组件?
How to use p.coords.latitude.toFixed(2) value to pass it for example to h:inputtext component?
你需要意识到 JSF 在 webserver 上运行并产生一堆 HTML/CSS/JS 代码从 webserver 发送到 webbrowser 并且 webbrowser 只运行HTML/CSS/JS.右键单击 webbrowser 中的页面并选择查看源代码.代替 <h:inputText> 你会看到类似
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
<input type="text" id="formid:inputid" />
在 JS 中,您可以使用 document 函数轻松地从 HTML DOM 中获取 HTML 元素并对其进行修改.
In JS, you can easily grab HTML elements from the HTML DOM using document functions and alter it.
var input = document.getElementById('formid:inputid');
input.value = 'new value';
这篇关于如何将 JavaScript 值传递给 JSF EL 和支持 bean?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
在 Angular 2/Typescript 中使用 IScrollUse IScroll in Angular 2 / Typescript(在 Angular 2/Typescript 中使用 IScroll)
Anime.js 在 Ionic 3 项目中不起作用anime.js not working in Ionic 3 project(Anime.js 在 Ionic 3 项目中不起作用)
Ionic 3 - 使用异步数据更新 ObservableIonic 3 - Update Observable with Asynchronous Data(Ionic 3 - 使用异步数据更新 Observable)
Angular 2:在本地 .json 文件中找不到文件Angular 2: file not found on local .json file(Angular 2:在本地 .json 文件中找不到文件)
在 Ionic 2 中,如何创建使用 Ionic 组件的自定义指In Ionic 2, how do I create a custom directive that uses Ionic components?(在 Ionic 2 中,如何创建使用 Ionic 组件的自定义指令?)
将 ViewChild 用于动态元素 - Angular 2 &离子2Use ViewChild for dynamic elements - Angular 2 amp; ionic 2(将 ViewChild 用于动态元素 - Angular 2 amp;离子2)