带有Primefaces的ClassCastException GMap OverlaySelect事件

时间:2016-11-30 17:22:44

标签: jsf primefaces classcastexception primefaces-gmap

我想在Gmap的infoWindow中显示一些数据。代码如下:

<p:gmap center="#{mybean.latitude}, #{mybean.longitude}" zoom="15" 
                    type="ROADMAP" model="#{mybean.mymapModel}" >
        <p:ajax event="overlaySelect" listener="#{mybean.onMarkerSelect}" />  
        <p:gmapInfoWindow >  
            <div class="popup_title prem">Address:</div>
            <div class="popup_address">#{mybean.markerAll.street}, #{mybean.markerAll.zipcode} #{mybean.markerAll.city}</div>
        </p:gmapInfoWindow>  
</p:gmap>

和My ManagedBean

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

在我的本地计算机上开发工作正常。单击标记时,数据(地址)将显示在infoWindow中。
在制作中,我看到很多ClassCastException喜欢:

FullAjaxExceptionHandler: An exception occurred during processing JSF ajax request. Error page '/error.jsf' will be shown.    
    java.lang.ClassCastException: java.lang.String cannot be cast 
        to com.mypackage.util.myHelperClass
        at com.mypackage.myBean.onMarkerSelect(myBean.java:416)
...
...

data的属性org.primefaces.model.map.Marker属于Object类型而非String

我做错了什么?为什么这个有时会起作用,有时候不起作用?

我使用的是Primefaces 5.3.7

1 个答案:

答案 0 :(得分:0)

我认为它错过了MyHelperClass的大写字母m - myHelperClass

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