简体   繁体   English

Primefaces Google Map-拖动标记后出现空指针异常

[英]Primefaces google map - null pointer exception after dragging marker

I am using primefaces (JSF) to intergrate google maps in my web application. 我正在使用Primefaces(JSF)将Google地图集成到我的Web应用程序中。

However, after following the tutorial on http://www.primefaces.org/showcase/ui/gmapDraggableMarkers.jsf I am encountering a Null Pointer Exception from the primefaces renderer as follows 但是,在按照http://www.primefaces.org/showcase/ui/gmapDraggableMarkers.jsf上的教程进行操作之后,我遇到了来自primefaces渲染器的Null指针异常,如下所示

20:48:45,741 INFO  [javax.enterprise.resource.webcontainer.jsf.context] java.lang.NullPointerException: java.lang.NullPointerException
        at org.primefaces.component.gmap.GMapRenderer.decode(GMapRenderer.java:62) [:]
        at javax.faces.component.UIComponentBase.decode(UIComponentBase.java:787) [:2.1.1-FCS]
        at javax.faces.component.UIComponentBase.processDecodes(UIComponentBase.java:1181) [:2.1.1-FCS]
        at com.sun.faces.context.PartialViewContextImpl$PhaseAwareVisitCallback.visit(PartialViewContextImpl.java:506) [:2.1.1-FCS]
        at com.sun.faces.component.visit.PartialVisitContext.invokeVisitCallback(PartialVisitContext.java:183) [:2.1.1-FCS]
        at javax.faces.component.UIComponent.visitTree(UIComponent.java:1589) [:2.1.1-FCS]
        at javax.faces.component.UIComponent.visitTree(UIComponent.java:1600) [:2.1.1-FCS]
        at javax.faces.component.UIComponent.visitTree(UIComponent.java:1600) [:2.1.1-FCS]
        at javax.faces.component.UIForm.visitTree(UIForm.java:344) [:2.1.1-FCS]
        at javax.faces.component.UIComponent.visitTree(UIComponent.java:1600) [:2.1.1-FCS]
        at javax.faces.component.UIComponent.visitTree(UIComponent.java:1600) [:2.1.1-FCS]
        at com.sun.faces.context.PartialViewContextImpl.processComponents(PartialViewContextImpl.java:376) [:2.1.1-FCS]
        at com.sun.faces.context.PartialViewContextImpl.processPartial(PartialViewContextImpl.java:252) [:2.1.1-FCS]
        at javax.faces.context.PartialViewContextWrapper.processPartial(PartialViewContextWrapper.java:183) [:2.1.1-FCS]
        at javax.faces.component.UIViewRoot.processDecodes(UIViewRoot.java:931) [:2.1.1-FCS]
        at com.sun.faces.lifecycle.ApplyRequestValuesPhase.execute(ApplyRequestValuesPhase.java:78) [:2.1.1-FCS]
        at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101) [:2.1.1-FCS]
        at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118) [:2.1.1-FCS]
        at javax.faces.webapp.FacesServlet.service(FacesServlet.java:409) [:2.1.1-FCS]
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:324) [:6.0.0.Final]
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:242) [:6.0.0.Final]
        at com.abc.filters.CityAdminProtFilter.doFilter(AbcProtFilter.java:58) [:]
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:274) [:6.0.0.Final]
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:242) [:6.0.0.Final]
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:275) [:6.0.0.Final]
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191) [:6.0.0.Final]
        at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:181) [:6.0.0.Final]
        at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:88) [:6.0.0.Final]
        at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.invoke(SecurityContextEstablishmentValve.java:100) [:6.0.0.Final]
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127) [:6.0.0.Final]
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) [:6.0.0.Final]
        at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:158) [:6.0.0.Final]
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) [:6.0.0.Final]
        at org.jboss.web.tomcat.service.request.ActiveRequestResponseCacheValve.invoke(ActiveRequestResponseCacheValve.java:53) [:6.0.0.Final]
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:362) [:6.0.0.Final]
        at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:877) [:6.0.0.Final]
        at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:654) [:6.0.0.Final]
        at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:951) [:6.0.0.Final]
        at java.lang.Thread.run(Thread.java:662) [:1.6.0_23]

Do you have any indication where this is coming from? 您有任何迹象表明这是从哪里来的吗? What I noticed is that the markerDragListener is not being called and the exception happens before it is called. 我注意到的是,没有调用markerDragListener,并且在调用之前发生了异常。

The following is the code I am using for rendering the map, etc. : 以下是我用于渲染地图等的代码:

<p:gmap id="gmap" center="41.381542, 2.122893" zoom="10" type="HYBRID" style="width:380px;height:350px"
                            model="#{attractionsBean.mapModel}"
                            markerDragListener="#{attractionsBean.onMarkerDrag}"/>

and

public void onMarkerDrag(MarkerDragEvent event) {  
    Marker marker = event.getMarker();  

    if (mapModel.getMarkers().size() > 0) {
        mapModel.getMarkers().get(0).setLatlng(marker.getLatlng());
        System.out.println("Updated marker location: " + "Lat:" + marker.getLatlng().getLat() + ", Lng:" + marker.getLatlng().getLng());
    }
    FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO, "Marker Dragged", "Lat:" + marker.getLatlng().getLat() + ", Lng:" + marker.getLatlng().getLng()));  
}

Thanks in advance!! 提前致谢!!

    else if(params.containsKey(clientId + "_markerDragged")) {
        String id = params.get(clientId + "_markerId");
        Marker marker = (Marker) model.findOverlay(id);
        double lat = Double.valueOf(params.get(clientId + "_lat"));
        double lng = Double.valueOf(params.get(clientId + "_lng"));
        marker.setLatlng(new LatLng(lat, lng));

        map.queueEvent(new MarkerDragEvent(map, marker));

    } 

The marker object is null, this happened to me because I was overriding the restoreState method of the component and changing the state 标记对象为null,这是发生在我身上的原因,因为我重写了组件的restoreState方法并更改了状态

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM