无法使用PrimeFaces使用Google地图坐标填充表格 [英] Can't populate table with Google Map coordinates using PrimeFaces

查看:114
本文介绍了无法使用PrimeFaces使用Google地图坐标填充表格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用PrimeFaces的bean和JSF视图的问题。我需要使用与标记关联的Google地图坐标填充表格。这几乎完成了,只有一些小事情在进行。有人可以给一个方向吗?

I have a problem with a bean and a JSF view using PrimeFaces. I need to populate a table with Google Maps coordinates associated with markers. It is almost done, there is just some little thing in the way. Someone can give a direction?

以下是bean:

Here is the bean:

import java.io.Serializable;  
import java.util.ArrayList;
import java.util.List;

import javax.faces.application.FacesMessage;   
import javax.faces.bean.ManagedBean;
import javax.faces.context.FacesContext;  
import javax.faces.event.ActionEvent;  

import org.primefaces.model.map.DefaultMapModel;  
import org.primefaces.model.map.LatLng;  
import org.primefaces.model.map.MapModel;  
import org.primefaces.model.map.Marker;
@SuppressWarnings("serial")
@ManagedBean
public class MapBean implements Serializable {  

    private MapModel emptyModel;  

    private String title;  

    private double lat;  

    private double lng;

    private List<LatLng> coordenadas;

    public List<LatLng> getCoordenadas() {
        return coordenadas;
    }

    public void setCoordenadas(List<LatLng> coordenadas) {
        this.coordenadas = coordenadas;
    }

    public MapBean() {  
        emptyModel = new DefaultMapModel();  
    }  

    public MapModel getEmptyModel() {  
        return emptyModel;  
    }  

    public void addMessage(FacesMessage message) {  
        FacesContext.getCurrentInstance().addMessage(null, message);  
    }  

    public String getTitle() {  
        return title;  
    }  

    public void setTitle(String title) {  
        this.title = title;  
    }  

    public double getLat() {  
        return lat;  
    }  

    public void setLat(double lat) {  
        this.lat = lat;  
    }  

    public double getLng() {  
        return lng;  
    }  

    public void setLng(double lng) {  
        this.lng = lng;  
    }

    public void populateTable(List<LatLng> lista){
        lista.add(new LatLng(getLat(), getLng()));
    }

    public void addMarker(ActionEvent actionEvent) {  
        Marker marker = new Marker(new LatLng(lat, lng), title);  
        coordenadas = new ArrayList<LatLng>();
        emptyModel.addOverlay(marker);  

        addMessage(new FacesMessage(FacesMessage.SEVERITY_INFO, "Marker Added", "Lat:" + lat + ", Lng:" + lng));

        populateTable(coordenadas);

    }

}

这里是查看主面标签。会发生什么事情是:添加标记,其他所有工作,但坐标不会到桌子上,我找不到原因。尽管如此,仍在尝试:

Here is the view, with the prime faces tag. What happens is: the markers are added, everything else works, but the coordinates do not go to the table and I can´t find out why. Still trying here though:

<!DOCTYPE html>  

  <html xmlns="http://www.w3.org/1999/xhtml"
  xmlns:h="http://java.sun.com/jsf/html"
  xmlns:a4j="http://richfaces.org/a4j"
  xmlns:rich="http://richfaces.org/rich"
  xmlns:p="http://primefaces.org/ui"
  xmlns:f="http://java.sun.com/jsf/core"
  xmlns:ui="http://java.sun.com/jsf/facelets">   

  <h:head>  
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false">    </script>   
  </h:head>   
  <h:body>  
  <h:form prependId="false">  
 <p:growl id="messages" showDetail="true" />  
<p:gmap id="gmap" center="-3.12808313259846,-59.9729442607909" zoom="13" type="ROADMAP"   
style="width:1200px;height:600px"  
model="#{mapBean.emptyModel}"   
onPointClick="handlePointClick(event);"   
widgetVar="map" />  

     <p:dialog widgetVar="dlg" effect="FADE" effectDuration="0.5" fixedCenter="true"            closable="false" >  

    <h:panelGrid columns="2">  
        <h:outputLabel for="title" value="Title:" />  
        <p:inputText id="title" value="#{mapBean.title}" />  

        <f:facet name="footer">  
            <p:commandButton value="Add"   
                    actionListener="#{mapBean.addMarker}"   
                    update="messages"   
                    oncomplete="markerAddComplete()"/>  
            <p:commandButton value="Cancel" onclick="return cancel()"/>  
        </f:facet>  
    </h:panelGrid>  

    <h:inputHidden id="lat" value="#{mapBean.lat}" />  
    <h:inputHidden id="lng" value="#{mapBean.lng}" />  

</p:dialog>
<p:dataTable  value="#{mapBean.coordenadas}" var="latLng">
        <p:column headerText="Latitude">  
            <h:outputText value="#{mapBean.lat}" />  
        </p:column>  

        <p:column headerText="Longitude">  
          <h:outputText value="#{mapBean.lng}" />  
       </p:column>           
</p:dataTable>  

非常感谢。

Thanks a lot.

推荐答案

Problem solved with theese changes in the view:


actionListener =#{mapBean.addMarker}
update =messages,tabela
oncomplete =markerAddComplete()/>
< p:commandButton value =取消onclick =return cancel()/>

必须更新tabela,这是另一个primefaces元素的id:

Had to update "tabela" wich is the id of another primefaces element:

<p:dataTable id="tabela" value="#{mapBean.coordenadas}" var="LatLng">
        <p:column headerText="Latitude">  
            <h:outputText value="#{LatLng.lat}" />  
        </p:column>  

        <p:column headerText="Longitude">  
          <h:outputText value="#{LatLng.lng}" />  
       </p:column>           
</p:dataTable>

这篇关于无法使用PrimeFaces使用Google地图坐标填充表格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆