Class 9 Prep Exercises
-
Let's add validation to our
edit
handlers. If you haven't set up edit functionality in yourcheese-mvc
app, you can add it by following the steps in class 8 prep exercises.In the
edit
handler that displays the form, you should already be passing in theCheese
object to be edited. This means that we can refactor the form in theedit.html
template 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
CheeseType
enum values, as we did in theadd.html
form from the lesson video. You'll want to pre-select the specific option that is already stored on the given object.In the
edit
handler that processes the form, validate the model and respond appropriately. - Add an integer property to
Cheese
to 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.html
template - Test!
- Add the property to