Develop the Mock User Interface
Explore how to develop a mock user interface for managing customer data using Java, JSP, and JavaScript. Understand methods for loading data, creating, updating, editing, viewing, and deleting records within a one-to-one bi-directional relationship. This lesson helps you build interactive UI components that consume mock services for intuitive server-side data handling.
Let’s turn from developing the mock service with an in-memory database to developing the user interface, which will ingest this mock service, as shown in Figure 4-2. The user interface will have ways to add, edit, delete, and show all records related to the Customer, including the Cart amount field.
JSP page
The JSP body is the starting page that gets loaded, and subsequently, the JavaScript methods are called. We will define the flow with the JavaScript calls.
loadObjects method
First, let’s look at the JavaScript loadObjects method which is called when the page is loaded with the onload event.
processResponseData service
The processResponseData JavaScript method that is called when the above service call is successful is revealed in the following code. The table is occupied with the contents of the in-memory database. The generateTableData JavaScript method is shown, which generates the table structure.
methodCall method
We have seen the page loading mechanism. If you see the JSP fragment, you will realize that the JavaScript method, methodCall, is being called. This works for both the create and update functionalities.
create method
First, we will see the create JavaScript method that takes the input from the text boxes name and amount and passes the input as a CustomerDto without an identifier.
update method
Next, we will look at the updated JavaScript method that updates a CustomerDto, including an identifier, name, and amount.
editObject and viewObject methods
We will also look at the JavaScript methods editObject and viewObject that show a record to be edited.
deleteObject method
Finally, we will look at the delete operation where the customer identifier is passed as an input and the related Customer information is removed and refreshed.
In the next lesson, let’s learn how to create the resource tier.