emnadridi / gmaps4jsf

Automatically exported from code.google.com/p/gmaps4jsf
0 stars 0 forks source link

Map does not render with JSF 2.0 on GlassFish #149

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?

Using Netbeans 6.9.1, create a Maven-built project for a EE 6 web application.  
Note: their template is a bit busted, you have to manually create a 
faces-config.xml file or else the Faces Servlet won't process your facelet 
scripts.

Here is the page in index.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://java.sun.com/jsf/html" xmlns:m="http://code.google.com/p/gmaps4jsf/">
    <h:head>
        <title>Attempt to get gmaps4jsf to work</title>
                <script
            src="http://maps.google.com/maps?file=api&amp;v=2&amp;key=yaddayadda"
            type="text/javascript">
        </script>

    </h:head>
    <h:body>
        This is my starting page.   It will not last long.
        <h:form>
            <hr/>
            <m:map width="300px" height="300px" />
            <h:commandButton value="do nothing" action="index" />
        </h:form>
    </h:body>
</html>

In the pom.xml file, add the repository:

        <repository>
            <id>googlecode.com</id>
            <url>http://gmaps4jsf.googlecode.com/svn/trunk/gmaps4jsf-repo</url>
        </repository>

And the dependency:

        <dependency>
            <groupId>com.googlecode.gmaps4jsf</groupId>
            <artifactId>gmaps4jsf-core</artifactId>
            <version>1.1.3</version>
        </dependency>

Note -- the later versions of the artifact don't work -- you can't use 1.1.3u3 
for example because maven can't find the pieces it needs.

Run the application.

What is the expected output? What do you see instead?

You see everything rendered on the page except for the map.  The space 
specified in the map element is reserved, but blank.  This is with both Safari 
and with Chrome.  BTW this is on a iMac with the latest Snow Leopard.

With Safari, you can look in the activity window and you can see the script in 
the header has been downloaded from google.  It is 11.5KB in size.  WIth 
Chrome, you can see error messages from console:  (sorry no cut and paste here 
I have to type it):

UnCaught TypeError:  maps.google.com/maps? (rest of URL is from the src 
attribute above) Object #<a Document> has no method 'write'
Uncaught ReferenceError: GMap2 is not defined.

I am sure there is something very basic wrong here, but I can't find what it 
is.  Any pointers much appreciated.

Original issue reported on code.google.com by OmegaObj...@gmail.com on 3 Oct 2010 at 5:17

GoogleCodeExporter commented 8 years ago
OK, with some google searching I think I have found out what is going on.   
This turns out to be a gmaps api problem, not an issue with gmaps4jsf.  However 
it would be nice if gmaps4jsf could implement a work-around since it seems to 
be something of a persistent problem.

I'll put the answer I have here for those who have run into this:

To work around this problem, enclose the facelets code in an <f:view 
contentType="text/html"> tag.  By default Faces will render the facelet as an 
XML document, and this otherwise unnecessary tag will cause it to render an 
HTML document.

The difference is that for the browser, an HTML document has a Document.write() 
method and the XML document does not.  The gmap api library depends on that 
method call.  So if you are including the gmaps API in your pages, they have to 
be HTML and not XHTML documents.  

I am not sure what workaround gmaps4jsf could provide, but it would have to be 
in some form of wrapper script in the header that would intercept that method 
invocation and do something with it.  It would be better fixed in gmaps API.

Original comment by OmegaObj...@gmail.com on 4 Oct 2010 at 3:10

GoogleCodeExporter commented 8 years ago

Original comment by Hazem.sa...@gmail.com on 29 Oct 2010 at 1:04