Class 9 Prep Exercises
-
Let's add validation to our
edithandlers. If you haven't set up edit functionality in yourcheese-mvcapp, you can add it by following the steps in class 8 prep exercises.In the
edithandler that displays the form, you should already be passing in theCheeseobject to be edited. This means that we can refactor the form in theedit.htmltemplate to useth:object="${cheese}"and then useth:field="*{propertyName}"to help render the inputs. Don't forget to modify the<label>elements to useth:for="propertyName". Add error message elements for each of the properties.You'll also want to pass in the list of all
CheeseTypeenum values, as we did in theadd.htmlform from the lesson video. You'll want to pre-select the specific option that is already stored on the given object.In the
edithandler that processes the form, validate the model and respond appropriately. - Add an integer property to
Cheeseto allow the user to give each cheese a rating. Follow these steps:- Add the property to
Cheese.java, along with validation annotations to allow the user to enter a value between 1 and 5 - Add the form input, label, and error message display to
templates/cheese/add.html - Display the rating in
templates/cheese/index.html - Add the rating to the
edit.htmltemplate - Test!
- Add the property to