【问题标题】:Passing a Named Bean variable as parameter of the Primefaces gmap function in a PF dialog box在 PF 对话框中将命名 Bean 变量作为 Primefaces gmap 函数的参数传递
【发布时间】:2018-11-07 15:46:19
【问题描述】:

我想在 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> 

lat/long 的 Bean 变量的值是正确的,但没有传入 primefaces gmap 函数,其中 lat/long 变量的值在生成的 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
   }
 );

结果是一个空白屏幕,显示以下 Chrome 控制台消息: pf.cw() 函数行上的“Uncaught SyntaxError: missing ) after argument list”。

所以 2 个问题:

第一:为什么Bean变量没有很好的传递给Primesfaces JS函数?

第二个,对我来说不太重要:为什么经度参数的第一个 0 似乎会在参数列表之后生成这个“Uncaught SyntaxError: missing )”。

非常感谢,并道歉,我是 JSF 的新手,对 JAVASCRIPT 的了解非常少;-)

【问题讨论】:

  • 对于缺失的 bean 值:bean 中的值何时填充?尝试在对话框中使用dynamic=true。这将呈现对话框内容,显示时间,而不是在 DOM 生成期间。
  • 首先,EL前面有一个空格。其次,地图前面的 EL 显示了什么(如果您将其设为 -#{gererAnnoncesMB.coordonneesGPS}-(前导和尾随减号以查看“边界”)

标签: google-maps primefaces jsf-2


【解决方案1】:

感谢您的时间和回答。

我不知道动态参数,我现在就用它;-)

对于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 中的 getter:

    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。 如果我解决了这个问题,我会稍后进行调查并让你发布。

非常感谢

问候 埃尔韦

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-12-23
    • 1970-01-01
    • 2021-11-21
    • 1970-01-01
    • 2011-12-24
    • 1970-01-01
    • 2018-05-25
    • 1970-01-01
    相关资源
    最近更新 更多