How to Use the Map Viewer and GeoCoder Components

The MapViewer sample application utilizes two Java Blueprint's 1.4 Catalog components written by Roger Kitain and modified for a Creator 2 sample by Craig McClanahan.  This sample is based on Craig's Creator sample.  The GeoCoder uses the Yahoo map service to verify the entered address and to get the exact latitude and longitude.  This information is then used by the MapViewer component to render and center the Google map.  Currently the early access sample application only presents the first address returned from the Yahoo map service.  The tag library for the MapViewer & GeoCoder components can be accessed using the declaration:

 <%@taglib prefix="ui" uri="http://java.sun.com/blueprints/ui/14"%>

The Map Viewer component uses a backing bean to provide the necessary information to render the Google map.  This information is populated by user input, and from the return of the GeoCoder component's Yahoo lookup.  These components can be used independently, but the exact latitude and longitude is required by the Map Viewer component to center the returned Google map.  To see how to use the GeoCoder component look at the "findAction" method of the com.sun.javaee.blueprints.mapviewer.MapBean backing bean.  It encapsulates the entire call and return of the GeoCoder and sets the values that are used by the Map Viewer.

An example of the JSF Map Viewer component's use is as follows:
 <ui:mapViewer id="mapViewerx" center="#{MapBean.mapPoint}" info="#{MapBean.mapMarker}"
markers="#{MapBean.locations}" style="height: 500px; width: 700px"/>
As you can see above, the component tag name is "mapViewer" and has the following attributes whose values are populated by the MapBean backing bean:
Since the GeoCode and the MapViewer accesses external services a proxy server will be needed if you are situated behind a firewall and isn't set to use a transparent proxy.  The setting of the proxy server's host and port  has prompts on the main lookup page, but security permissions will need to be granted to set the System property values.  To grant write access to set the JVMs proxy settings, the server.policy will have to be altered to include write permission.  For Glassfish the server.policy file resides under the domain's config directory.  For example if the domain is named "domain1" the file is located at .../glassfish/domains/domain1/config/server.policy.  The PropertyPermission should be altered to add write permission, which would look like the following:
    permission java.util.PropertyPermission "*","read,write";

NOTE: If the sample application is accessed through a URL other than "http://localhost:8080/bp-map-viewer" then a new map KEY will have to generated to access the Google map service.  The key is currently free and can be generated from http://www.google.com/apis/maps/.  The resultant key can be placed in the Map Viewer component's "key" attribute or placed in the WEB-INF/web.xml deployment descriptor under the param-name com.sun.j2ee.blueprints.ui.mapviewer.KEY.  For example:

    <param-name>com.sun.j2ee.blueprints.ui.mapviewer.KEY</param-name>
    <param-value>ABQIAAAAyQYKk4__l80DyIsqLPvvuxTRFLl8Tcq3arEgFHYFeOMvEMiJ8RQehhrYXPIDrf1muScWAd1MXrlVkQ</param-value>


© Sun Microsystems 2006. All of the material in The Java BluePrints Solutions Catalog is copyright-protected and may not be published in other works without express written permission from Sun Microsystems.