Google maps primefaces p:gmap在复合组件中,OverlySelectEvent为null 环境:

Google maps primefaces p:gmap在复合组件中,OverlySelectEvent为null 环境:,google-maps,jsf,jakarta-ee,primefaces,Google Maps,Jsf,Jakarta Ee,Primefaces,1、玻璃鱼3.1 2,primefaces 3.0.1 要求: 1、开发一个名为“corpInfoMap”的复合组件,将公司在谷歌地图中的位置显示为“标记”。当用户单击标记时,在MapInfo窗口中显示公司的信息 2、开发另一个名为“corpInfoMapDialog”的复合组件,它是一个包含“corpInfoMapDialog”的p:对话框 问题: 无论是在页面还是在对话框中,地图都非常有效。但当用户单击地图中的标记时: 传递到侦听器方法的“OverlySelectEvent”(事件)为空。因

1、玻璃鱼3.1

2,primefaces 3.0.1

要求: 1、开发一个名为“corpInfoMap”的复合组件,将公司在谷歌地图中的位置显示为“标记”。当用户单击标记时,在MapInfo窗口中显示公司的信息

2、开发另一个名为“corpInfoMapDialog”的复合组件,它是一个包含“corpInfoMapDialog”的p:对话框

问题: 无论是在页面还是在对话框中,地图都非常有效。但当用户单击地图中的标记时:

传递到侦听器方法的“OverlySelectEvent”(事件)为空。因此,“event.getOverlay()”抛出NullPonterException。

代码: 1 corpInfoMap.xhtml 4 CorporationMapModel.java
公共类CorporationMapModel实现可序列化{
私人上市公司;//企业列表 公司名单
私有MapModel模型;//地理信息模型面映射模型
私有字符串centerJd;//地图中间位置-经度 液化天然气
专用字符串中心;//地图中间位置-维度 拉特
私有字符串缩放;//地图缩放级别 gmap变焦
专用标记选择标记器;//被选择的标记选定标记(覆盖)
private int width=600;//映射的宽度(px)
private int height=480;//地图的高度(px)
公共模型(公司){
上市公司=新ArrayList();
if(corporation!=null){
增加(公司);
}
公司(法团);;
}
公共模型(上市公司){
corporates=corporates==null?新建ArrayList():corporates;
公司(法团);;
}
私有无效CalInfo公司(){
if(model==null)
模型=新的DefaultMapModel();
model.getMarkers().clear();
if(corporates!=null&&corporates.size()>0){
适用于(公司:公司){
CorporationMapInfo mapInfo=CorporationMapInfo.generateNewCorporationMapInfo(公司);
如果(mapInfo!=null){
model.addOverlay(mapInfo);
}
}
List markers=model.getMarkers();
if(markers!=null&&markers.size()>0){
双最大值=0D;
双最小值=0D;
双maxJd=0D;
双minJd=0D;
对于(int i=0;iwd?wd:minWd;
minJd=minJd>jd?jd:minJd;
}
}
BigDecimal centerWd=新的BigDecimal((最大值+最小值)/2D);
BigDecimal centerJd=新的BigDecimal((maxJd+minJd)/2D);
centerWd=centerWd.setScale(6,BigDecimal.四舍五入半向上);
centerJd=centerJd.setScale(6,大十进制。向上舍入半个整数);
setCenterWd(centerWd.toPlainString());
setCenterJd(centerJd.toPlainString());
zoom=GoogleMapZoom.getZoom(maxWd,minWd,maxJd,minJd,width,height);
}
}
}
MarkerSelect上的公共无效(OverlySelectEvent事件){
selectedMarker=(Marker)event.getOverlay();
}
上市公司(){
返回公司;
}
上市公司(上市公司){
corporates=corporates==null?新建ArrayList():corporates;
这是指公司;
Calinfo公司();
}
公共映射模型getModel(){
收益模型;
}
公共字符串getCenterJd(){
返回中心jd;
}
公共无效setCenterJd(字符串centerJd){
this.centerJd=centerJd;
}
公共字符串getCenterWd(){
返回中心轴;
}
公共无效设置中心线(字符串中心线){
this.centerWd=centerWd;
}
公共字符串getZoom(){
返回缩放;
}
公共void集缩放(字符串缩放){
this.zoom=zoom;
}
公共标记getSelectedMarker(){
返回所选标记;
}
公共int getWidth(){
返回宽度;
}
公共void setWidth(int-width){
这个。宽度=宽度;
}
公共整数getHeight(){
返回高度;
}
公共空间设置高度(内部高度){
高度=高度;
}
公共void集合模型(MapModel模型){
this.model=模型;
}
公共无效集selectedMarker(Marker selectedMarker){
this.selectedMarker=selectedMarker;
}
}
5 js.xhtml(“js”表示“reduce”,而不是“javascript”),此xhtml文件中的重要部分:

我所做的: 我在谷歌上搜索了很多,但都没有答案

2,我已经调试过了,我发现事件对象是由primefaces生成的(至少在AjaxBehaviorRenderer.decode(FacesContext context,UIComponent component,ClientBehavior)方法中,事件对象是存在的,而不是空的。)

3,在JlltWssbDjjsbEditPage.setSelectedMarker(OverlySelectEvent事件)的方法中,事件为null

谢谢大家! 我希望我已经说清楚了

顺致敬意,
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html 
    xmlns="http://www.w3.org/1999/xhtml" 
    xmlns:cc="http://java.sun.com/jsf/composite" 
    xmlns:p="http://primefaces.org/ui" 
    xmlns:ui="http://java.sun.com/jsf/facelets" 
    xmlns:h="http://java.sun.com/jsf/html" 
    xmlns:c="http://java.sun.com/jsp/jstl/core" 
    xmlns:f="http://java.sun.com/jsf/core"
>
<cc:interface displayName="单位地理信息">
    <cc:attribute name="mapModel" required="true" displayName="地理信息Model,com.ui.fwjg.viewModel.CorporationMapModel类型" />
    <cc:attribute name="selectedListener" required="true" method-signature="void method(org.primefaces.event.map.OverlaySelectEvent)" displayName="选择锚点的方法" />
</cc:interface>
<cc:implementation>
    <f:view contentType="text/html">
    <p:gmap zoom="#{cc.attrs.mapModel.zoom}" 
            type="HYBRID" 
            center="#{cc.attrs.mapModel.centerWd},#{cc.attrs.mapModel.centerJd}" 
            style="width:#{cc.attrs.mapModel.width}px;height:#{cc.attrs.mapModel.height}px;"
            model="#{cc.attrs.mapModel.model}"
            >
        <p:ajax event="overlaySelect" listener="#{cc.attrs.selectedListener}"></p:ajax>
         <p:gmapInfoWindow rendered="#{cc.attrs.mapModel.selectedMarker != null}" maxWidth="#{cc.attrs.mapModel.width / 2}">
            <p:outputPanel style="text-align:center;display:block;margin:auto:" rendered="#{cc.attrs.mapModel.selectedMarker != null}">
                <h:panelGroup style="width:100%;font-size:1.5em;line-height:2em;font-weight:bold;text-align:center;">
                    #{cc.attrs.mapModel.selectedMarker.data.dwmc}
                </h:panelGroup>
                <h:panelGroup layout="block" styleClass="com-ui-clearboth"></h:panelGroup>
                <h:graphicImage rendered="#{not empty cc.attrs.mapModel.selectedMarker.data.dwsltFile}" 
                                style="max-width:#{cc.attrs.mapModel.width / 2};display:block;margin:20px auto;" 
                                url="/file.ui?f=#{cc.attrs.mapModel.selectedMarker.data.dwsltFile}"></h:graphicImage> 
                <h:outputText value="#{mapBean.marker.title}" />
                <h:panelGroup layout="block" styleClass="com-ui-clearboth"></h:panelGroup>
                <h:outputText rendered="#{not empty cc.attrs.mapModel.selectedMarker.dwjj}" 
                                value="&lt;p style=&quot;font-size:1em;line-height:1.5em;text-indent:2em;&quot;&gt;"
                                escape="false"></h:outputText>
                    <h:outputText rendered="#{not empty cc.attrs.mapModel.selectedMarker.dwjj}" value="#{cc.attrs.mapModel.selectedMarker.dwjj}">
                    </h:outputText>
                <h:outputText rendered="#{not empty cc.attrs.mapModel.selectedMarker.dwjj}" value="&lt;/p&gt;" escape="false"></h:outputText>
            </p:outputPanel> 
        </p:gmapInfoWindow>  
    </p:gmap>
    </f:view>
</cc:implementation>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html 
    xmlns="http://www.w3.org/1999/xhtml" 
    xmlns:cc="http://java.sun.com/jsf/composite" 
    xmlns:p="http://primefaces.org/ui" 
    xmlns:ui="http://java.sun.com/jsf/facelets" 
    xmlns:h="http://java.sun.com/jsf/html" 
    xmlns:c="http://java.sun.com/jsp/jstl/core" 
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:comuicommon="http://java.sun.com/jsf/composite/components/ui/common">
<!-- INTERFACE -->
<cc:interface displayName="单位地理信息窗口">
    <cc:attribute name="mapModel" required="true" displayName="地理信息Model,com.ui.fwjg.viewModel.CorporationMapModel类型" />
    <cc:attribute name="selectedListener" required="true" method-signature="void method(javax.faces.component.behavior.AjaxBehavior)" displayName="选择锚点的方法" />
    <cc:attribute name="dialogId" default="corpInfoMapDialog" displayName="对话框的ID" />
</cc:interface>
<cc:implementation>
    <p:dialog header="单位地理信息" widgetVar="#{cc.attrs.dialogId}" id="#{cc.attrs.dialogId}" width="#{cc.attrs.mapModel.width}">
        <h:panelGroup rendered="#{cc.attrs.mapModel != null and cc.attrs.mapModel.model != null and (not empty cc.attrs.mapModel.model.markers)}" layout="block">
            <comuicommon:corpInfoMap mapModel="#{cc.attrs.mapModel}" selectedListener="#{cc.attrs.selectedListener}"/>
        </h:panelGroup>
        <h:panelGroup rendered="#{not (cc.attrs.mapModel != null and cc.attrs.mapModel.model != null and (not empty cc.attrs.mapModel.model.markers))}" 
                    layout="block" style="font-size:2em;text-align:center;">
            该单位无地理信息。
        </h:panelGroup>
    </p:dialog>
</cc:implementation>
</html>
@ManagedBean
@ViewScoped
public class JlltWssbDjjsbEditPage  implements Serializable{

    ... // a lot of lines
    private CorporationMapModel corporationMapModel;

    @PostConstruct
    public void init() {
        corporationMapModel = new CorporationMapModel();
        ... // other codes, have no business with corporationMapModel.
    }

    // the OverlaySelectEvent listener method
    // when user click the marker in map, this method is invoked, but the parameter "evnet" is null.
    public void setSelectedMarker(OverlaySelectEvent event){
        corporationMapModel.onMarkerSelect(event);
    }

    public CorporationMapModel getCorporationMapModel() {
        return corporationMapModel;
    }

    public void setCorporationMapModel(CorporationMapModel corporationMapModel) {
        this.corporationMapModel = corporationMapModel;
    }

    // reset the jsb, reset the corporationMapModel's properties(only it's properties, neither it nor the mapModel in it.)
    public void setJsb(JlltWssbDjjsb jsb) {
        this.jsb = jsb;
        Corporation corporation = jsb == null ? null : (jsb.getWineInfo() == null ? null : jsb.getWineInfo().getCorporation());
        corporationMapModel.resetModel(corporation);
        setShowHistory(jsb != null);
        initWineInfo();
    }

    ... // a lot of lines, have no business with 
}
public class CorporationMapModel implements Serializable{
    private List<Corporation> corporations; // 企业列表 corporation list
    private MapModel model; // 地理信息Model primefaces map model
    private String centerJd; // 地图中间位置-经度 lng
    private String centerWd; // 地图中间位置-维度 lat
    private String zoom; // 地图缩放级别 gmap zoom
    private Marker selectedMarker; // 被选择的Marker selected marker(overlay)
    private int width = 600; // the width(px) of the map
    private int height = 480; // the height(px) of the map 

    public void resetModel(Corporation corporation) {
        List<Corporation> corporations = new ArrayList<Corporation>();
        if(corporation != null){
            corporations.add(corporation);
        }
        setCorporations(corporations);
    }
    public void resetModel(List<Corporation> corporations) {
        corporations = corporations == null ? new ArrayList<Corporation>() : corporations;
        setCorporations(corporations);
    }

    private void calInfosByCorporations() {
        if(model == null)
            model = new DefaultMapModel();
        model.getMarkers().clear();
        if (corporations != null && corporations.size() > 0) {
            for (Corporation corporation : corporations) {
                CorporationMapInfo mapInfo = CorporationMapInfo.generateNewCorporationMapInfo(corporation);
                if (mapInfo != null) {
                    model.addOverlay(mapInfo);
                }
            }
            List<Marker> markers = model.getMarkers();
            if (markers != null && markers.size() > 0) {
                double maxWd = 0D;
                double minWd = 0D;
                double maxJd = 0D;
                double minJd = 0D;
                for (int i = 0; i < markers.size(); i++) {
                    Marker marker = markers.get(i);
                    if (i == 0) {
                        maxWd = marker.getLatlng().getLat();
                        minWd = marker.getLatlng().getLat();
                        maxJd = marker.getLatlng().getLng();
                        minJd = marker.getLatlng().getLng();
                    } else {
                        double wd = marker.getLatlng().getLat();
                        double jd = marker.getLatlng().getLng();
                        maxWd = maxWd < wd ? wd : maxWd;
                        maxJd = maxJd < jd ? jd : maxJd;
                        minWd = minWd > wd ? wd : minWd;
                        minJd = minJd > jd ? jd : minJd;
                    }
                }
                BigDecimal centerWd = new BigDecimal((maxWd + minWd) / 2D);
                BigDecimal centerJd = new BigDecimal((maxJd + minJd) / 2D);
                centerWd = centerWd.setScale(6, BigDecimal.ROUND_HALF_UP);
                centerJd = centerJd.setScale(6, BigDecimal.ROUND_HALF_UP);
                setCenterWd(centerWd.toPlainString());
                setCenterJd(centerJd.toPlainString());
                zoom = GoogleMapZoom.getZoom(maxWd, minWd, maxJd, minJd, width, height);
            }
        }
    }

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

    public List<Corporation> getCorporations() {
        return corporations;
    }

    public void setCorporations(List<Corporation> corporations) {
        corporations = corporations == null ? new ArrayList<Corporation>() : corporations;
        this.corporations = corporations;
        calInfosByCorporations();
    }

    public MapModel getModel() {
        return model;
    }

    public String getCenterJd() {
        return centerJd;
    }

    public void setCenterJd(String centerJd) {
        this.centerJd = centerJd;
    }

    public String getCenterWd() {
        return centerWd;
    }

    public void setCenterWd(String centerWd) {
        this.centerWd = centerWd;
    }

    public String getZoom() {
        return zoom;
    }

    public void setZoom(String zoom) {
        this.zoom = zoom;
    }

    public Marker getSelectedMarker() {
        return selectedMarker;
    }
    public int getWidth() {
        return width;
    }
    public void setWidth(int width) {
        this.width = width;
    }
    public int getHeight() {
        return height;
    }
    public void setHeight(int height) {
        this.height = height;
    }
    public void setModel(MapModel model) {
        this.model = model;
    }
    public void setSelectedMarker(Marker selectedMarker) {
        this.selectedMarker = selectedMarker;
    }
}
<h:form id="dwMapForm">
            <comuicommon:corpInfoMapDialog
                mapModel="#{jlltWssbDjjsbEditPage.corporationMapModel}"
                selectedListener="#{jlltWssbDjjsbEditPage.setSelectedMarker(org.primefaces.event.map.OverlaySelectEvent)}"
                dialogId="dwMapDialog"
            />
</h:form>