binding of <p:gmap component doesn't work - Primefaces 3.4.1

冷暖自知 提交于 2019-12-24 18:12:21

问题


I'm using the p:gmap component in an application, but when I try to use the binding attribute to reference a GMap in a bean, it doesn't work and the map is not showed.

JSF code:

<p:gmap binding="#{mapBean.map}" center=" -26.9995, -49.686" zoom="11" type="ROADMAP" />

Backing bean code:

public GMap getMap() {
    map = new GMap();
    map.setCenter("-26.9995, -49.686");
    map.setZoom(11);
    map.setType("ROADMAP");
    map.setModel(geoModel);
    map.setStyle("width:850px;height:450px");
    map.setWidgetVar("vMap");
    return map;
}

When I used this component without binding, and it worked normally...

Primefaces version 3.4.1; Glassfish 3.1.2.2

Any idea?

Thanks


回答1:


I found the same problem related for you... When I use the binding attribute to reference GMap in a Managed Bean, the map isn't rendered.

I noticed that the file gmap.js was not been loading and for this reason GMap was not been rendered too.

I didn't get to find out the cause of this problem, but I found a way to solve it, but is not an elegant way. :D

I added this line in my xhtml file after copy gmap.js to file system of directory structure of the project.

<h:head>
    ...
    <h:outputScript library="primefaces" name="gmap/gmap.js" />
    ...
</h:head>

I hope this help you! Good luck! :D




回答2:


An alternative it's to create a GMap instance on Backed Bean (or whatever component that presents this case), Create the Component xhml view, remove binding xhtml propperty and match every propperty of both, like this example:

Bean:

// #{viewBean}
private GMap googleMap;
@PostConstruct
public void onPostConstruct(){
    googleMap.setDisableDoubleClickZoom(Boolean.TRUE);
    googleMap.setScrollWheel(Boolean.FALSE);
    googleMap.setCenter(getMapCenterString());
    googleMap.setZoom(mapZoomLevel);
    googleMap.setType("NORMAL");
    googleMap.setFitBounds(Boolean.FALSE);
    // etc...
}
// getter and setter of googleMap

XHTML View:

<p:gmap id="gmap"
     center="#{viewBean.googleMap.center}" 
     zoom="#{viewBean.googleMap.zoom}"
     type="#{viewBean.googleMap.type}"
     model="#{viewBean.mapModel}"
     scrollWheel="#{viewBean.googleMap.scrollWheel}"
     disableDoubleClickZoom="#{viewBean.googleMap.disableDoubleClickZoom}"
     etc... />

So we can keep the control of component in backed bean.

While primefaces fixes this bug.



来源:https://stackoverflow.com/questions/13378153/binding-of-pgmap-component-doesnt-work-primefaces-3-4-1

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!