问题
I want to open a Gmap inside my jsf page, i tried these sample but it didn't work:
<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:p="http://primefaces.org/ui">
<h:head>
<script src="http://maps.google.com/maps/api/js?sensor=false"
type="text/javascript"></script>
</h:head>
<body>
<ui:composition template="/WEB-INF/template/template.xhtml">
<ui:define name="content">
<p:commandButton type="button" icon="ui-icon-pin-s" value="Show Map"
onclick="dlg.show()" />
<p:dialog widgetVar="dlg" width="625" height="400" modal="true">
<p:gmap center="41.381542, 2.122893" zoom="15" type="HYBRID"
style="width:600px;height:400px" widgetVar="mymap" />
</p:dialog>
</ui:define>
</ui:composition>
</body>
</html>
回答1:
Your mistake is: in composition, you have to include <h:head></h:head> to apply css, but any code from that have not been loaded. You need to add script to /WEB-INF/template/template.xhtml
template.xhtml:
<h:head>
// other here
<script src="http://maps.google.com/maps/api/js?sensor=false"
type="text/javascript"></script>
</h:head>
See also:understand the purpose of jsf ui:composition
来源:https://stackoverflow.com/questions/16368842/primefaces-gmmap-inside-a-dialog-not-rendering