Ray
Ray

Reputation: 1828

Primefaces gmap doesn't show after click on p:commandButton (ReferenceError: google is not defined )

I see gmap just after update page. If I don't update page I get error in chrome console

Uncaught ReferenceError: google is not defined index.xhtml:1
Failed to execute 'write' on 'Document': It isn't possible to write into a document from an asynchronously-loaded external script unless it is explicitly opened. 

<h:body>
    <ui:composition template="/WEB-INF/template/layout_template.xhtml">
        <ui:define name="windowTitle">
            Admin Panel
        </ui:define>
        <ui:define name="content">
            <h:form>            

            <div class="panel panel-default">
                <div class="panel-heading">Map</div>
                <div class="panel-body">
                    <p:gmap type="roadmap" center="50.00, 28.00" zoom="8" style="width: 1000px; height: 400px;"/>
                </div>
            </div>
            </h:form>

            <!--<h:outputScript name="app/google-map-loader.js" library="js" target="head"/>-->
            <script src="https://maps.googleapis.com/maps/api/js?sensor=false" type="text/javascript">
            </script>
        </ui:define>
    </ui:composition>

</h:body>
</html>

My footer template

<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://xmlns.jcp.org/jsf/html" xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
        >

<body>
<ui:composition>
    <div class="bottom-nav footer"> 2013 &copy; by Me</div>
    <!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
    <script src="http://code.jquery.com/jquery-latest.min.js" type="text/javascript"></script>
    <h:outputScript name="lib/bootstrap.min.js" library="js" target="body"/>
    <h:outputScript name="app/smooth-sliding-menu.js" library="js" target="body"/>
</ui:composition>
</body>
</html>

I read in doc script position

But I don't want put gmap script in head of main template. Is it posiible to make it work without redirect. And is it possible to add script in head of child template

Upvotes: 0

Views: 1875

Answers (1)

Ray
Ray

Reputation: 1828

I found the solution for this problem. On previous page I have p:commandButton

<p:commandButton value="Login" action="#{loginBean.navigateToDashboard()}" ajax="false"
                                 styleClass="btn btn-default btn-block"/>

I doesn't have ajax="false" attribute but page was changed I don't know why. Now, with non-ajax submit I don't get any problems.

Upvotes: 1

Related Questions