Page navigation
As introducing the feature pieces of the MVC specification, we have visited most of views in this demo. In fact, when you desgin a website, you should have a map for the page navigation among all views.View navigation summary
- When the appliation starts up, it will display the task list view.
- User can create a new task by clicking the New Task button, the task creating view is displayed.
- When user input the task title and description, submit the form.
- If the task is submitted successfully, return the main task list view. The new created task should be in the list.
- If the task form data is invalid, show the validation errors.
- User can edit the new created task by click edit icon.
- It will read the task from database and fill the existing data into form fields
- The submission progress is similiar with the new task subflow described in above 3.
- User can update the task status(TODO to DOING, or DOING to DONE). When the status is changed successfully, return to the task list.
- User can delete the DONE task. When it is deleted, return to the task list.
View navigation path definition
We have used GET, POST, PUT, DELETE http methods to process basic CRUD operations, listed in the following table.Navigation path | HTTP method | View page | Descritption |
---|---|---|---|
/tasks | GET | tasks.jspx | Task list view |
/tasks/new | GET | add.jspx | Display new task view |
/tasks | POST | redirect:tasks | Submit task form, save task, and redirect to task list view |
/tasks/{id}/edit | GET | edit.jspx | Display edit task view |
/tasks/{id} | PUT | redirect:tasks | Submit task form, update task, and redirect to task list view |
/tasks/{id} | DELETE | redirect:tasks | Submit task form, delete task, and redirect to task list view |
/tasks/{id}/status | PUT | redirect:tasks | Submit task form, update task status, and redirect to task list view |
Display views
In the above paths, the task list view, new task view and edit task view can display the views directly via inputing the url path in browser locaiton bar. Others are POST submission, they will redirect to the task list view.There are several approaches provided in MVC specification to navigate the view path.
- Add
@View
annotation to avoid
controller method. - Return a
Viewable
object to a controller method. -
Return a
Response
entity which body content includes the view path.
public Response someAction(){ return Response.ok("redirect:tasks").build(); }
-
Return a
String
type value directly.
public String someAction(){ return "redirect:tasks"; }
POST-REDIRECT-GET pattern
The new task form submission and edit task form submission follow the POST-REDIRECT-GET pattern.- When the form is submitted successfully, a form POST request is sent to the server.
- After the server received the request, and processed it, it will REDIRECT to the target view.
- And perform a new GET request on the target view.
Source codes
-
Clone the codes from my github.com account.
https://github.com/hantsy/ee8-sandbox/
- Open the mvc project in NetBeans IDE.
- Run it on Glassfish.
- After it is deployed and runging on Glassfish application server, navigate http://localhost:8080/ee8-mvc/mvc/tasks in browser.
评论