|
|
|||||||||||
Carol McDonald's Blog
«Sample Catalog Application using using JRuby and Rails |
Main
| dojo 1.0 Presentation slides and Sample code »
Adding a Google Map to the Sample JSF Catalog ApplicationPosted by caroljmcdonald on October 19, 2007 at 02:50 PM | Comments (8)Adding a Google Map to the Sample JSF Catalog Application
| |||||||||||
Code Sample from: Detail.jsp |
|
commandLink
is used to provide a link to click on to
display a Google map corresponding to the address
displayed by the value
tag. The commandLink
tag represents an HTML hyperlink and is rendered as an HTML <a> element. The
commandLink
tag is used to submit an action event
to the application. This commandLink action
attribute
references a MapBean
ManagedBean which is defined in the
faces-config.xml file:| Code Sample from: faces-context.xml |
|
MapBean mapAction method
gets the longitude and latitude for the address
and returns the logical outcome
String map, which causes the navigation to go to the map.jsp page.
This MapBean
mapAction method
is defined as shown below:| Code Sample from: MapBean.java |
|
import
com.sun.j2ee.blueprints.ui.geocoder.GeoCoder; import com.sun.j2ee.blueprints.ui.geocoder.GeoPoint; import com.sun.j2ee.blueprints.ui.mapviewer.MapMarker; import com.sun.j2ee.blueprints.ui.mapviewer.MapPoint; import javax.faces.context.FacesContext; public class MapBean { private MapMarker mapMarker=new MapMarker(); private MapPoint mapPoint=new MapPoint(); private String location=""; public MapMarker[] getLocations() { return new MapMarker[]{this.mapMarker}; } ItemController
itemController = (ItemController)FacesContext.getCurrentInstance().getExternalContext().getSessionMap().get("item");Item().getAddress();location=address.getStreet1()
+ COMMA + address.getCity()+ COMMA + address.getState() +blueprints
GeoCoder to get points based on location (this uses
Yahoo's map service)mapMarker.setLatitude(points[0].getLatitude());mapMarker.setLongitude(points[0].getLongitude()); |
mapAction
method, the FacesContext is
used to get the ItemController
in order to get the current store Item's
Address.
Then the findLocation is called, which uses the blueprints GeoCoder component. The blueprints GeoCoder
uses the Yahoo map service to verify the entered address and to get the
exact latitude and longitude.
NavigationHandler
matches the logical outcome, map
against the navigation rules in the application configuration resource
file faces-config.xml
to determine which page to access next. In this case, the
JavaServer Faces implementation loads the map.jsp
page after this method returns.| Code Sample from: faces-config.xml |
<navigation-rule>map</from-outcome> |
map.jsp the blueprints
JSF mapViewer
component uses the latitude and longitude to render the Google map :| Code Sample from: Map.jsp |
|
mapViewer
component uses the MapBean
to provide the necessary information, which was returned from the GeoCoder
component's Yahoo lookup, to render the Google map. mapViewer
center attribute is populated by a com.sun.j2ee.blueprints.ui.mapviewer.MapPoint
which is accessed through the MapBean
backing bean. The mapPoint is used
to center the map utilizing the latitude and longitude from the mapPoint.mapViewer
info
attribute holds the address string text that is printed in the
information balloon that is shown with the map.mapViewer
markers
attribute holds an Array of com.sun.j2ee.blueprints.ui.mapviewer.MapMarker
objects that represent points to be identified on the map.
This example only populates the Array with the first point returned
from the GeoCoder.
Is the source code available for the bp-ui-15.jar? A number of phase listeners throw null pointers when accessing the viewRoot in our environment
Posted by: cobar on October 23, 2007 at 09:00 AM
I think you can get the source code here
https://blueprints.dev.java.net/servlets/ProjectDocumentList?folderID=4144&expandFolder=4144&folderID=0
or here
https://blueprints.dev.java.net/source/browse/blueprints/
it is in the directory
blueprints\bpcatalog\ee5\components\ui\src\java\com\sun\javaee\blueprints\components\ui\mapviewer
You can read more about it here:
http://java.sun.com/developer/technicalArticles/J2EE/mashup_2/
http://java.sun.com/developer/technicalArticles/J2EE/mashup_1/
Posted by: caroljmcdonald on October 23, 2007 at 09:13 AM
Hi,
I have following the code example in this article, but I am not able to make Map Show up on my jsf page.
I didn't get any error or exception for that.
Do I need to have bp-ui15.jar for this? I am using jdk1.5.
Posted by: debby_li on March 07, 2008 at 04:25 PM
Yes you need the bp-ui jar . You can download my example.
Posted by: caroljmcdonald on March 07, 2008 at 08:50 PM
I use bp-ui-14.jar from your example, otherwise, I will get run time error. I create the application by simplifying your example without webservice, and no glassfish. I use MapBean.jsp by modifying the mapAction() methods as
public String mapAction() {
this.location = "1020 Kifer Rd, sunnyvale, CA,94086";
return findLocation();
}
and in Detail.jsp, I have a command link to map.jsp
I also modify faces-config:
map
/map.jsp
I still can't get the map displayed, can you advice what might be wrong?
Posted by: debby_li on March 10, 2008 at 12:53 PM
ok.. I found my problem. I will also need shale-remoting.jar file.
Posted by: debby_li on March 10, 2008 at 02:28 PM
hi, is it possible for me to label alphabetic for each marker?
I would like to specify multiple location in the map.
and wondering how to label each one.
do you know is a place I can find the java doc for com.sun.j2ee.blueprints.ui.mapviewer.MapMarker class as well?
Thanks.
Posted by: debby_li on March 19, 2008 at 02:48 PM
see How to Use the Map Viewer and GeoCoder Components at https://blueprints.dev.java.net/complib/v2/map-viewer.html
Posted by: caroljmcdonald on March 19, 2008 at 03:18 PM
|
|