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
- In the Project Explorer view, expand ticket-monster→src→main.
- Right-click webapp and click → .
- 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
.
Figure 2.20. New HTML File using the New HTML File Wizard
- Click.
- From the Templates list, select HTML5 jQuery Mobile Page (1.4) and click . This creates a
mobile.html
file that is automatically opened in the Visual/Source tab of the Visual Page Editor.Figure 2.21. Selected HTML5 jQuery Mobile Page (1.4) Template in New HTML File Wizard
- 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"); });
Figure 2.22. Completed
mobile.html
File - 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 . 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.
Figure 2.23. Events Displayed via Mobile Interface in External Web Browser