aseychell
aseychell

Reputation: 1804

Primefaces google map - null pointer exception after dragging marker

I am using primefaces (JSF) to intergrate google maps in my web application.

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

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.

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!!

Upvotes: 0

Views: 2024

Answers (1)

jwatters
jwatters

Reputation: 11

    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

Upvotes: 1

Related Questions