Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/jsf/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Google maps JSF PrimeFaces 6.1p:gmap不使用谷歌地图渲染多段线_Google Maps_Jsf_Primefaces - Fatal编程技术网

Google maps JSF PrimeFaces 6.1p:gmap不使用谷歌地图渲染多段线

Google maps JSF PrimeFaces 6.1p:gmap不使用谷歌地图渲染多段线,google-maps,jsf,primefaces,Google Maps,Jsf,Primefaces,对于项目需求,我需要使用primefaces 6.1 p:gmap标记渲染多段线,但只渲染贴图。这是我的XHTML文件: <?xml version='1.0' encoding='UTF-8' ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <htm

对于项目需求,我需要使用primefaces 6.1 p:gmap标记渲染多段线,但只渲染贴图。这是我的XHTML文件:

<?xml version='1.0' encoding='UTF-8' ?>
<!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:h="http://xmlns.jcp.org/jsf/html"
      xmlns:p="http://primefaces.org/ui" xmlns:f="http://xmlns.jcp.org/jsf/core">
<h:head>
    <title>Facelet Title</title>
    <script src="https://maps.google.com/maps/api/js?key=SOME_KEY" defer="defer"
            type="text/javascript"></script>
<h:outputScript library="primefaces" name="gmap/gmap.js" />
</h:head>
<h:body>
    <f:view contentType="text/html">
        <h:form id="form1">
            <p:gmap center="36.883707, 30.689216" zoom="15" type="MAP" style="width:900px;height:800px;"
                    model="#{mapBean.model}" id="myMap"/>
        </h:form>
    </f:view>
</h:body>
</html>

添加到MapBean模型的多段线不会通过p:gmap属性显示。只显示地图。我使用Spring Boot 1.2.3运行primefaces 6.1和Mojarra 2.2.11。是否有任何想法/指针指向我可能缺少的任何东西,或者这是p:gmap和多段线渲染的真正问题?我还查看了Chrome Javascript控制台,没有显示任何错误。

已解决。感谢@Kukeltje的帮助。 似乎当我们使用Spring框架(我使用SpringBoot 1.2.3来运行这个应用程序)来管理事情时,我们需要使用Bean的@Named注释来为模型服务

这是我为它工作所做的改变

XHTML与原始代码帖子(如上)中的内容保持一致 Bean代码(如下所示)


在这里效果很好:找到差异哦,你会错过bean的范围声明。并且
位于错误的位置(它位于
h:head
之外)@Kukeltje我已经做了更改(请参见使用更改编辑的原始代码帖子),但它仍然没有呈现多段线。我遵循您发布的primefaces链接中的示例。您是否能够在您的终端尝试,并让它知道,如果它的工作或任何其他指针将不胜感激。
import org.primefaces.model.map.DefaultMapModel;
import org.primefaces.model.map.LatLng;
import org.primefaces.model.map.MapModel;
import org.primefaces.model.map.Polyline;

import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import java.io.Serializable;

@RequestScoped
@ManagedBean(name = "mapBean")
public class MapBean implements Serializable {

    private MapModel model;

    @PostConstruct
    public void MapBean() {
        model = new DefaultMapModel();
        Polyline polyline = new Polyline();
        polyline.getPaths().add(new LatLng(36.879466, 30.667648));
        polyline.getPaths().add(new LatLng(36.883707, 30.689216));
        polyline.getPaths().add(new LatLng(36.879703, 30.706707));
        polyline.getPaths().add(new LatLng(36.885233, 30.702323));

        polyline.setStrokeWeight(8);
        polyline.setStrokeColor("#FF9900");
        polyline.setStrokeOpacity(0.9);

        model.addOverlay(polyline);
    }

    public MapModel getModel() {
        return this.model;
    }
}
import org.primefaces.model.map.DefaultMapModel;
import org.primefaces.model.map.LatLng;
import org.primefaces.model.map.MapModel;
import org.primefaces.model.map.Polyline;

import javax.annotation.PostConstruct;
import javax.inject.Named;
import java.io.Serializable;

@Named("mapBean")
public class MapBean implements Serializable {
    public void setModel(MapModel model) {
        this.model = model;
    }

    private MapModel model;

    @PostConstruct
    public void MapBean() {
        model = new DefaultMapModel();
        Polyline polyline = new Polyline();
        polyline.getPaths().add(new LatLng(36.879466, 30.667648));
        polyline.getPaths().add(new LatLng(36.883707, 30.689216));
        polyline.getPaths().add(new LatLng(36.879703, 30.706707));
        polyline.getPaths().add(new LatLng(36.885233, 30.702323));
        polyline.setStrokeWeight(8);
        polyline.setStrokeColor("#FF9900");
        polyline.setStrokeOpacity(0.9);
        model.addOverlay(polyline);
    }
    public MapModel getModel() {
        return this.model;
    }
}