2013-05-21 29 views
4

我建立一个简单的Web应用程序,显示来自Google地图的地图与多个标记从我的数据库加载渲染......但我不能让它呈现......谷歌地图将不会在JSF

我使用JSF 2和gmaps4jsf。

我的页面看起来是这样的:

<!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://java.sun.com/jsf/html" 
     xmlns:f="http://java.sun.com/jsf/core" 
     xmlns:ui="http://java.sun.com/jsf/facelets" 
     xmlns:m="http://code.google.com/p/gmaps4jsf/"> 

[...] 
<m:map width="500px" latitude="10.1" longitude="10.1" height="500px" zoom="6" autoReshape="true"> 
    <ui:repeat var="loc" value="#{locs}"> 
     <m:marker latitude="#{loc.latitude}" longitude="#{loc.longitude}"> 
      <m:htmlInformationWindow htmlText="#{loc.latitude}-#{loc.longitude}" /> 
     </m:marker> 
    </ui:repeat> 
</m:map> 
[...] 

我从应该工作的例子复制的代码......但我不能看地图。

我在我的classpath上有gmaps4jsf-core-3.0.0.jar,我想我不需要配置任何其他的东西......任何想法?

编辑:看来标签不被识别。当我点击浏览器中的“查看源代码”时,gmaps标记没有被“翻译”,它们会在我写入xhtml文件时显示出来。

回答

4

如果您的标签没有被翻译,最可能的是该jar文件位于错误的地方。有些东西正在避免你的web应用程序找到它。你怎么建造它?

将最新的库jar放入您的web应用程序WEB-INF/lib文件夹中。

您的米:地图必须在h:表格标记。

由于你的库版本,你应该包括JavaScript代码:

<script type="text/javascript" 
    src="https://maps.googleapis.com/maps/api/js?sensor=true"> 
</script> 

看看这个simple example for using gmaps4jsf2 library

你有没有用第一个非常基本的配置工作?

<!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:ui="http://java.sun.com/jsf/facelets" 
     xmlns:h="http://java.sun.com/jsf/html" 
     xmlns:f="http://java.sun.com/jsf/core" 
     xmlns:m="http://code.google.com/p/gmaps4jsf/"> 
<ui:composition xmlns="http://www.w3.org/1999/xhtml" 
       xmlns:ui="http://java.sun.com/jsf/facelets" 
       template="/template/base-template.xhtml"> 
    <ui:define name="js"> 
     <script type="text/javascript" 
       src="https://maps.googleapis.com/maps/api/js?sensor=true"> 
     </script> 
    </ui:define> 
    <ui:define name="title"> 
     This is the new title 
    </ui:define> 
    <ui:define name="content"> 
     <h1>Simple Map with a marker and an InfoWindow</h1> 

     <h:form id="form"> 
      <m:map width="500" height="450px" latitude="37.13" longitude="22.43" enableScrollWheelZoom="true"> 
       <m:marker> 
        <m:htmlInformationWindow htmlText="This is Sparta, Greece"/> 
       </m:marker> 
      </m:map> 
     </h:form> 
    </ui:define> 
</ui:composition> 
</html> 

问候,

+0

当我回家,让你知道会发生什么,我会尝试这个,谢谢:) – diminuta

+1

伟大的!你救了我的一天:D它现在有效! – diminuta

+0

欢迎您! =) –