Red Hat Training

A Red Hat training course is available for Red Hat JBoss Developer Studio

2.11. Add a User Interface Optimized for Mobile Devices

The TicketMonster user interface displays on desktop and mobile clients but it is not optimized for the latter. The procedure below uses the jQuery Mobile API to create a mobile optimized user interface. The mobile user interface created varies from the existing user interface by displaying the names of the events returned by the previously created web service rather than the Member Registration web page.

Procedure 2.11. Add a User Interface Optimized for Mobile Devices

  1. In the Project Explorer view, expand ticket-monstersrcmain.
  2. Right-click webapp and click NewHTML file.
  3. Complete the information about the file as follows:
    • In the Enter or select the parent folder field, type ticket-monster/src/main/webapp.
    • In the File name field, type mobile.html.
    In the Enter or select the parent folder field, type ticket-monster/src/main/webapp. In the File name field, type mobile.html and click Next.

    Figure 2.20. New HTML File using the New HTML File Wizard

  4. Click Next.
  5. From the Templates list, select HTML5 jQuery Mobile Page (1.4) and click Finish. This creates a mobile.html file that is automatically opened in the Visual/Source tab of the Visual Page Editor.
    From the Templates list, select HTML5 jQuery Mobile Page and click Finish.

    Figure 2.21. Selected HTML5 jQuery Mobile Page (1.4) Template in New HTML File Wizard

  6. List the events returned by the web service in the mobile user interface by adding the following lines immediately after the alert("Ready To Go"); line
    $.getJSON("rest/events", function(events) {
    	// console.log("returned are " + events);
    	var listOfEvents = $("#listOfItems");
    	listOfEvents.empty();
    	$.each(events, function(index, event) {
    		// console.log(event.name);
    		listOfEvents.append("<li><a href='#'>" + event.name + "</a>");
        });
        listOfEvents.listview("refresh");
    });
    
    To list the events returned by the web service in the mobile user interface, add the lines given immediately after the alert("Ready To Go"); line

    Figure 2.22. Completed mobile.html File

  7. Save the mobile.html file.
View the mobile interface, by opening an external web browser and in the address bar entering http://localhost:8080/ticket-monster/mobile.html. At the Ready To Go prompt, click OK. The names of the events in the database are displayed.

Note

HTML pages are deployed immediately so there is no need to do a full publish of the TicketMonster application to see changes.
To view the mobile interface, open a Web Browser tab and in the address bar enter http://localhost:8080/ticket-monster/mobile.html. At the Ready To Go prompt, click OK. The names of the events in the database are displayed.

Figure 2.23. Events Displayed via Mobile Interface in External Web Browser