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

Red Hat logoGithubRedditYoutubeTwitter

Learn

Try, buy, & sell

Communities

About Red Hat Documentation

We help Red Hat users innovate and achieve their goals with our products and services with content they can trust.

Making open source more inclusive

Red Hat is committed to replacing problematic language in our code, documentation, and web properties. For more details, see the Red Hat Blog.

About Red Hat

We deliver hardened solutions that make it easier for enterprises to work across platforms and environments, from the core datacenter to the network edge.

© 2024 Red Hat, Inc.