google-maps - 在 PF 对话框中将命名 Bean 变量作为 Primefaces gmap 函数的参数传递
问题描述
我想在 Primefaces 对话框中显示 Primefaces gmap。纬度/经度是一个命名 Bean 变量,并作为 Primefaces gmap 函数的参数,如下所示:
<ui:composition
xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui">
<p:dialog header="MAP" widgetVar="gmapDialog" appendTo="@(body)" modal="false" showEffect="fade" hideEffect="fade" resizable="true">
#{gererAnnoncesMB.coordonneesGPS}
<p:gmap id="gmap" center=" #{gererAnnoncesMB.coordonneesGPS}" zoom="15" type="terrain" style="width:600px;height:400px" />
</p:dialog>
纬度/经度的 Bean 变量的值是正确的,但未传入 primefaces gmap 函数,其中纬度/经度变量的值在生成的 HTML 代码中设置为“00.000000,00.000000”:
pf.cw(
"GMap",
"widget_formVisualisationAnnonce_gmap",
{
id:"formVisualisationAnnonce:gmap",
mapTypeId:google.maps.MapTypeId.TERRAIN,
center:new google.maps.LatLng(00.000000, 00.000000),
zoom:15,
fitBounds:false
}
);
结果是一个空白屏幕,在 pf.cw() 函数的行上显示以下 Chrome 控制台消息:“参数列表后未捕获语法错误:缺少)”。
所以2个问题:
第一:为什么Bean变量没有很好的传递给Primesfaces JS函数?
其次,对我来说不太重要:为什么经度参数的第一个 0 似乎会在参数列表之后生成这个“未捕获的语法错误:缺失 )”。
非常感谢,并道歉,我是 JSF 的新手,对 JAVASCRIPT 的了解非常少;-)
解决方案
感谢您的时间和答案。
我不知道动态参数,我现在将使用它;-)
对于EL之前的空间,实际代码中不存在,只是我这边的复制/粘贴错误(但无论如何我认为这没有影响)。
EL -#{gererAnnoncesMB.coordonneesGPS}- 写在地图之前,根据需要在屏幕上显示良好的 GPS 纬度/经度。似乎 getter 的第二次调用 (getGererAnnonceMB.coordonneesGPS()) 发送了一个“00.000000, 00.000000”值,我不明白为什么。
为了解决我的问题,我只需添加一个 JSTL EL 值(JSF 中的变量,而不是托管 Bean 中的变量)并将其放入 PF gmap 函数中。它现在正在工作。我知道这不是一个合适的解决方案(快速而肮脏的解决方案;-))...
<ui:composition
xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui"
xmlns:c="http://xmlns.jcp.org/jsp/jstl/core">
<p:dialog header="MAP" widgetVar="gmapDialog" appendTo="@(body)" modal="false" showEffect="fade" hideEffect="fade" resizable="true" dynamic="true">
<f:view contentType="text/html">
<h:outputText value="#{gererAnnoncesMB.coordonneesGPS}" title="coordonnées"/>
<c:set var="maVariable" value="#{gererAnnoncesMB.coordonneesGPS}" scope="request" />
<p:gmap id="gmap" center="#{maVariable}" zoom="15" type="terrain" style="width:600px;height:400px" />
</f:view>
</p:dialog>
托管 Bean GererAnnonceMB 中的吸气剂:
public String getCoordonneesGPS() {
coordonneesGPS = "00.000000, 00.000000"; // Coordonnées GPS de l'Annonce
if (annonceetendueSelected != null) {
coordonneesGPS = annonceetendueSelected.getVilLat() + ", " + annonceetendueSelected.getVilLon();
}
return coordonneesGPS;
}
在服务器日志中,我看到 annonceetendueSelected 的值不是 NULL。如果我解决了这个问题,我会稍后进行调查并让你发布。
非常感谢
问候埃尔韦
推荐阅读
- java - Java - 安全性已开启,但我仍然可以发送任何我想要的请求
- angular6 - 类型'void'上不存在属性'subscribe'中的angular6错误
- angular - 如何将按钮动态注入 Angular 6 应用程序?
- postgresql - ejabberd 和“调用未定义函数 pgsql:squery”
- javascript - 将事件监听器添加到 document.currentScript
- matlab - 根据像素值范围创建图像蒙版
- python-3.x - 如何从 python 中的另一个线程访问 Tkinter 小部件
- android - FirebaseInstanceIdService 已弃用
- python - keras 模型中损失函数的奇怪行为,具有预训练的卷积基础
- python-2.7 - 在所有解释器上运行 tox,包括宽和窄 2.7 编译的 Python