If you are implementing a Website using JSF and Java, and you want to add a Google Maps, there can be different solutions.
You can use one of the PrimeFaces components. There is a nice little component called GMap: http://www.primefaces.org/showcase/ui/gmapHome.jsf
However it is doesn’t offer every function we are used to have with a Google Map.
A better possibility is to use gmap4jsf. To add a Google Mao into your JSF Page you need to add the gmaps4jsf tab library.
Here is a simple Example of who you can use it:
<%@ taglib uri="http://code.google.com/p/gmaps4jsf/" prefix="m" %>
The Example in the attachment uses the latitude and longitude to present a marker on a specific point on the Google Map. The picture in the attachment presents the resulting outcome.
Further examples can be found using the following link:
http://www.mashups4jsf.com/gmaps4jsf-examples/home.jsf
The gmpas4jsf provides JSF tags that make it easy to create a map using latitude and longitude or an address. You can add a marker to the map or an information text. Also some nice additional function like a zoom in and out or switching between map types can be used.
You can read an overview about the functionalities of gmaps4jsf using the following link: http://code.google.com/p/gmaps4jsf/
To calculate your coordinates you can use the Java API for Google geocoder v3
An overview about the functionality and also information about the Maven Repository can be found under the following link: http://code.google.com/p/geocoder-java/
The geocoder is an easy possibility if you want to search for a specifiy city or route that you want to presents in your Google Map.
Steps
cd $GLASSFISH/bin
asadmin create-service --name "$SERVICENAME" $DOMAIN
C:\WINDOWS\system32\sc.exe create $SERVICENAME binPath= "$glassfish-root\lib\appservService.exe \"$glassfish-root\bin\asadmin.bat start-domain --user admin --passwordfile $glassfish-root\passwordfile $DOMAIN\" \"$glassfish-root\bin\asadmin.bat stop-domain $DOMAIN\"" start=auto DisplayName="$DISPLAYNAME"
Commands (only Glassfish v3)
Since GWT doesn't offer a native library supporting sound it is necessary to use an external gwt library. I ended up using GWT-sound, which in essence is a GWT wrapper of the JavaScript library SoundManager 2 that provides functionalities for playing audio.
To implement the audio player, the following steps were executed:
1. Create the GUI
2. Implement the GUI functionality
3. Implement the sound functionality
4. Initialize the audio player
For step 1 I created two buttons, one for play/resume/pause and one for stopping the sound file entirely:Button play = new Button("play");
Button stop = new Button("stop");
Step 2 was implementing the functionality of the GUI, which in essence should just call the respective sound methods by a click on a button:play.addClickHandler(new ClickHandler() {//onClick call play() or toggle()});
stop.addClickHandler(new ClickHandler() {//onClick call stop()});
To implement the audio functionality the class variable soundmanager was introduced that would handle the sound. SoundManager uses a String to identify a sound file:SoundManager soundmanager = SoundManager.getInstance();
final String soundId = "id";
public void play() {soundmanager.play(soundId);}
public void toggle() {soundmanager.togglePause(soundId);} //SoundManager uses same method for resuming and pausing
public void stop() {soundmanager.stop(soundId);}
In the last step it was necessary to load the sound file into the SoundManager and ensure the audio player wouldn't be played before the files were loaded. Otherwise it would result into an exception. For that purpose the buttons were disabled until the files were finished loading://disable buttons
...
//Assign the sound file to the soundmanager
sm.onLoad(new Callback() {
public void execute() {
soundmanager.createSound(soundId, "pathToTheFile");
}});
//enable the buttons after the sound file is assigned
soundmanager.getDefaultOptions().onLoad(new Callback() {
public void execute() {
//enable buttons
...
}});