我正在使用primefaces(JSF)在我的网络应用程序中集成谷歌地图。
但是,按照http://www.primefaces.org/showcase/ui/gmapDraggableMarkers.jsf上的教程后,我遇到了来自primefaces渲染器的Null Pointer Exception,如下所示
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]
你有什么指示来自哪里?我注意到的是没有调用markerDragListener,并且在调用它之前发生了异常。
以下是我用于渲染地图等的代码:
<p:gmap id="gmap" center="41.381542, 2.122893" zoom="10" type="HYBRID" style="width:380px;height:350px"
model="#{attractionsBean.mapModel}"
markerDragListener="#{attractionsBean.onMarkerDrag}"/>
和
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()));
}
提前致谢!!
答案 0 :(得分:1)
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));
}
标记对象为null,这发生在我身上,因为我重写了组件的restoreState方法并更改了状态