【问题标题】:gmap PrimeFaces p:ajaxgmap PrimeFaces p:ajax
【发布时间】:2011-08-20 04:04:59
【问题描述】:

我正在尝试在p:ajax 的帮助下使用新的纬度、经度来更新 PrimeFaces 的谷歌地图,但它不起作用......我正在使用 JSF 2.0。我之前以类似的方式使用过p:ajax,效果很好。知道为什么这不起作用吗?以下是代码,contForm是表单的id。

<h:outputText value="Latitude :"/>
<h:inputText value="#{confirmBrandRegistration.newBrand.mapLatitude}" size="10">
    <p:ajax event="blur" update="contForm:gMapID"/>
</h:inputText>
<h:outputText value=" Longitude :"/>
<h:inputText value="#{confirmBrandRegistration.newBrand.mapLongitude}" size="10" >
    <p:ajax event="blur" update="contForm:gMapID"/>
</h:inputText>
<h:outputText value=" Marker :"/>
<h:inputText value="#{confirmBrandRegistration.newBrand.mapMarker}" size="20" >
    <p:ajax event="blur" update="contForm:gMapID"
            listener="#{confirmBrandRegistration.updateMarker}"/>
</h:inputText>
</h:panelGrid>

<p:outputPanel id="gMapID">
    <f:view contentType="text/html">
        <p:gmap center="#{confirmBrandRegistration.newBrand.mapLatitude}, #{confirmBrandRegistration.newBrand.mapLongitude}" 
                zoom="16" type="HYBRID" streetView="true"
                model="#{confirmBrandRegistration.simpleModel}"
                style="width:500px;height:400px" />
    </f:view>
</p:outputPanel>

【问题讨论】:

  • 为什么在地图上使用&lt;f:view contentType="text/html"&gt;
  • 您还应该指出您使用的是哪个 PrimeFaces 版本。

标签: ajax jsf primefaces primefaces-gmap


【解决方案1】:

我现在解决了:)

索引页面:

<h:panelGroup id="pmap">
    <p:inputText value="#{mapManager.address}" label="Adresa" />
    <h:outputText value="#{mapManager.geo}" id="m" />
    <p:commandButton value="OK" actionListener="#{mapManager.updateMapCenter(ae)}" update="pmap" />
    <p:gmap  center="#{mapManager.geo}" 
             zoom="7" 
             type="HYBRID"    
             style="width:800px;height:400px" 
             streetView="true"
             model="#{mapManager.map}"
             overlaySelectListener="#{mapBean.onMarkerSelect}"
             >
        <p:gmapInfoWindow>  
            <p:outputPanel style="text-align:center; display:block; margin:auto:">
                <h:outputText value="#{mapManager.marker.title}" />  
                wserw
            </p:outputPanel>  
        </p:gmapInfoWindow>  
    </p:gmap>
</h:panelGroup>

托管 bean 的一部分:

private MapModel map;
private Marker marker;
private String address;
private String geo="49.817491999999992, 15.4729620";

public MapManager() {
}

@PostConstruct
public void init() {
    events = edao.findAll();
    map = new DefaultMapModel();
    for (Event event : events) {  
        Marker m=new Marker(new LatLng(event.getLat(), event.getLng()), event.getName());
        map.addOverlay(m);
    }
}

public void updateMapCenter(ActionEvent ae) {
    GMapService gs=new GMapService();
    LatLng geo=gs.getGeocode(address);
    this.geo=geo.getLat()+","+geo.getLng();
}

希望它能解决你的问题。

【讨论】:

  • 谢谢。记得当时用的时候解决了问题。。现在不记得上下文了。。。
  • 当今世界上的人们有什么问题。这个问题/答案被浏览了 3038 次(今天,当我写这个话题时),我是第一个为“两个”问题和答案添加 +1 投票的人?我为什么在这里?我试图在 PrimeFaces 论坛上帮助其他人,因此我将这个 stackoverflow 问题的 URL 提供给 PrimeFaces Core 论坛中最近提出的问题,这首先出现在谷歌搜索结果中。
  • 您的 primeFaces 版本是什么?我再也没有见过 gmap.overlaySelectListener 属性
  • GMapService是自己实现的类吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2014-08-01
  • 2017-01-01
  • 2011-06-12
  • 1970-01-01
  • 2014-03-29
  • 2014-08-25
  • 1970-01-01
相关资源
最近更新 更多