integrate a Google Map into a Website using JSF

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:
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="" 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:

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:

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:
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.


integrate a Google Map into a Website using JSF

The Challenge is to implement a Google Map into a Website. The should be option to add a mark on the map using for example the address or the latitude and longitude.

How to collaborate on a Java project

When working in team on a Java project, we want to be able to contribute to the code, even though sitting in different locations. The changes to the code should be synchronized, and it should be possible to comment on the recent changes.

Creating a Windows service for Glassfish


  1. Install a Glassfish Applications server from
  2. Open a Windows Command Line: Start Menu -> Run
  3. Change to your glassfish/bin directory

    cd $GLASSFISH/bin
  4. Execute the following command (for Glassfish v3):

    asadmin create-service --name "$SERVICENAME" $DOMAIN

    $SERVICENAME ... the name of your Windows service
    $DOMAIN... the name of your application domain in the glassfish
  5. Execute the following command (for Glassfish v2):

    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"

    $SERVICENAME ... the name of your Windows service
    $DOMAIN... the name of your application domain in the glassfish
  6. Check if your windows service was created correctly and set to start automatically:
    1. Goto: Start -> Administrative Tools -> Services
    2. Right klick on your service and select properties
    3. Check if Startup typ is set to Autmatic
  7. Klick Start, to start the service

Commands (only Glassfish v3)

  • To start the service from commandline: /path/to/$SERVICENAME start
  • To stop the service from commandline: /path/to/$SERVICENAME stop

Starting glassfish with a Windows service

Glassfish is a Java Enterprise Edition application server. If it is installed on a windows server it is necessary start it automatically, for example after a maintenance reboot. To achieve this goal the glassfish startup process has to be performed with a windows service.

Java applets don't work on Mac OS X

All webpages that use Java applets show a "Missing Plug-in" error message. Safari & Firefox both don't work.

Using SoundManager 2 with GWT to play sound

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() {;}
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


Creating a web audio player with GWT

Google Web Toolkit (GWT) is a set of tools that allows for creating JavaScript applications in Java. For a web application I was working on with GWT, I had to create an audiovisualization unit. For that purpose it was necessary to implement an audio player that would play/pause/resume/stop a sound file by request.

Reading webpages in Java applications

Many web application fall into the category of "mash ups", meaning that they collect information from different sources (often other web applications) and combine it in a single, coherent user interface that offers additional value to the user. Often this additional value is enough to justify the mash up as a service of its own. In order write such an application, one must first be able to access the web pages in question in the Java code of the own application.

Importing Data from different sources - SOA approach description

To make full use of the basic principles of the service oriented architecture it is useful to define a public/generally accepted model of the data object to be stored. This model has to encompass all (or at least most) of the possible data such an object could have and is later handled in the lowest level of the architecture, the data layer. In this layer the data objects can be handled by a database, so let’s assume we use JAVA as the basic language, the data objects could then be stored in an HSQLDB, accessible by a basic CRUD-interface.

Above, in the service layer a general import/export function must be defined, and while this general function should not be bound to one format it will have to work through the data object already described. This is, most often than not, the hardest part as these functions must cover and handle model specific data in an open way as to not limit the presentation of the data in the next layer and to still allow the CRUD to handle the data object without loss of information.

It was already mentioned that the next layer will be the presentation layer. This is the first layer where actual information on the various formats is used. In object oriented programming languages it is quite easy to realize this (abstract classes in Java for example), once the underlying layers are working properly. Here is also the only location in the program where there is a true difference in the representation of the data. While it was quite abstract and handled only to store and retrieve in the layers below, here it can be manipulated to fit certain formats or vies-versa so that certain formats fit the underlying data object.

By this approach it becomes possible to expand (and reduce) the formats a service is able to manage without changing the underlying service. This has a positive effect on the work time as well as consistency throughout such projects.


Subscribe to java