Today, I’ll add the ability to edit users. This will be easy, as most of the pieces are already in place. First, I’ll add a new editUser method that accepts an updated user object, verifies that the user exists and then saves the updated user object. The only differences between the new editUser method and the existing postUser method are:
- Invert the test on users.containsKey() to throw an error when the user does not exist (editUser) rather than when the user already exists (postUser).
- New method name and @Path annotation
diff --git a/src/main/java/com/ideoplex/tutorial/MyResource.java b/src/main/java/com/ideoplex/tutorial/MyResource.java
- Addition of bootbox for bootstrap based dialogs.
- Addition of an error function to the jQuery ajax invocation.
diff --git a/src/main/webapp/index.html b/src/main/webapp/index.html
Finally, I fleshed out the userEdit function by copying the body of the userPost function. The only difference here is in the url value used by the jQuery ajax function.
@@ -129,7 +133,21 @@
The current source for jersey-gson is available on github.