即使添加了叠加层,event.getOverlay也会返回null

时间:2013-11-28 11:23:58

标签: primefaces

我的xhtml代码段

<p:gmap id="gMap" center="17.483333,78.416667" zoom="15" type="ROADMAP" model="#{routeMapngSysMBean.simpleModel}" style="width: 1150px; height: 450px;">  
    <p:ajax event="overlaySelect" listener="#{routeMapngSysMBean.onMarkerSelect}" />  
    <p:gmapInfoWindow>  
        <p:outputPanel style="text-align:center;display:block;">
              <h:outputText value="#{routeMapngSysMBean.marker.data}" />
        </p:outputPanel>  
    </p:gmapInfoWindow>  
</p:gmap>       

RouteMappingMBean.java

import org.primefaces.event.map.OverlaySelectEvent;
import org.primefaces.model.map.DefaultMapModel;
import org.primefaces.model.map.LatLng;``
import org.primefaces.model.map.MapModel;
import org.primefaces.model.map.Marker;

@ManagedBean(name = "routeMapngSysMBean")
@SessionScoped
public class RouteMapngSysMBean extends AdminCommonMBean implements
    Serializable, WebConstants, ErrorConstants {
private MapModel simpleModel;

public RouteMapngSysMBean() {
    initiliaze();

    String zone_cd = httpServletRequest
            .getParameter("routeMapForm:location");

    String vendor_cd = httpServletRequest
            .getParameter("routeMapForm:vendor");

    String dDate = httpServletRequest.getParameter("routeMapForm:date");
    String slot = httpServletRequest.getParameter("routeMapForm:timeslot");
    try {
        if (orderMgmtBusn == null) {
            orderMgmtBusn = (OrderMgmtBusn) BeansUtil.getBean(facesContext,
                    "orderMgmtBusn");
        }
        simpleModel = new DefaultMapModel();
        if (ValidateUtil.isFieldNotEmpty(vendor_cd)
                && ValidateUtil.isFieldNotEmpty(zone_cd)
                && ValidateUtil.isFieldNotEmpty(dDate)
                && ValidateUtil.isFieldNotEmpty(slot)) {
                mapDetails = orderMgmtBusn.getMapDetails(vendor_cd,slot,dDate, zone_cd);
        }
        List<GMapDetails> latlang = mapDetails;
        for (GMapDetails var : latlang) {
            if (ValidateUtil.isFieldNotEmpty(var.getLatitude()) &&                 ValidateUtil.isFieldNotEmpty(var.getLongitude())) {
                firstName = var.getCustomerFName();
                customerId = var.getCustomerId();
                orderId = var.getOrderId();
                orderValue = var.getOrderValue();
                String Customerdetails = "\n CustomerName:"+firstName+"\n CustomerId:"+customerId+"\n OrderId:"+orderId+"\n OrderValue:"+orderValue;
                lat = Double.parseDouble(var.getLatitude());
                lng = Double.parseDouble(var.getLongitude());
                LatLng coord1 = new LatLng(lat, lng);
                simpleModel.addOverlay(new Marker(coord1, var.getLocationName(),Customerdetails));
            }
        }
    } catch (EMartBusnException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

}

public void initiliaze() {
    try {
        WebApplicationContext springContext = WebApplicationContextUtils
                .getWebApplicationContext((ServletContext) facesContext
                        .getExternalContext().getContext());
        if (emartAppBaseBusn == null) {
            emartAppBaseBusn = (EmartAppBaseBusn) springContext
                    .getBean("emartAppBaseBusn");
        }
        avilableStoreTypes = BeanMappingUtil
                .filterVendorZones(emartAppBaseBusn.retriveZones());
        retriveAllVendorsList = emartAppBaseBusn.retriveAllVendorsList();
        zonesList = BeanMappingUtil.filterVendorZones(emartAppBaseBusn
                .getZones());

    } catch (EMartBusnException e) {
        logger.error(e);
    }
}

public void onMarkerSelect(OverlaySelectEvent event) {  
    marker = (Marker) event.getOverlay();  
}   

public MapModel getSimpleModel() {
    return simpleModel;
}

public void setSimpleModel(MapModel simpleModel) {
    this.simpleModel = simpleModel;
} 

public Marker getMarker() {
    return marker;
}

1 个答案:

答案 0 :(得分:1)

请尝试从:

转换'simpleModel'字段声明

私有MapModel simpleModel;

为:

私有最终静态MapModel simpleModel = new DefaultMapModel();

...当然要删除它:'simpleModel = new DefaultMapModel();'来自构造函数。