0

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

Ray
  • 1,788
  • 7
  • 55
  • 92
  • You can execute/call a JavaScript method at any time and you don't need a redirect to achieve it. For the second question, you can use `h:outputScript` in child templates. –  Apr 23 '14 at 18:16
  • @SujanSivagurunathan I can't put external url inside `h:outputScipt` – Ray Apr 23 '14 at 18:18
  • `` should work inside a child template wrapped by a form. What's wrong ? –  Apr 23 '14 at 18:34
  • @SujanSivagurunathan I get 'Uncaught ReferenceError: google is not defined'. – Ray Apr 23 '14 at 18:39
  • Try to load the script before loading gmap. Put the script tag before gmap. –  Apr 23 '14 at 18:50
  • @SujanSivagurunathan It doesn't help – Ray Apr 23 '14 at 18:53
  • Add `&callback=initialize` to the script's URL. You might have encountered this [issue](http://stackoverflow.com/questions/14184956/async-google-maps-api-v3-undefined-is-not-a-function/14185834#14185834) –  Apr 23 '14 at 18:58
  • @SujanSivagurunathan with 'callback' appears new exception http://i.imgur.com/8xWmacY.png – Ray Apr 23 '14 at 19:54

1 Answers1

1

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.

Ray
  • 1,788
  • 7
  • 55
  • 92