Validations for the Play Framework

It can be very easy to add validations to the play framework. Just adding annotations to the objects will usually do the trick, but these are for the values of one field only, like @Required or @Email. If you want to check if some combined properties are valid, then you can use the @CheckWith annotation. With this annotation you have to define a class that will be used for the validation and optionally a message if this fails. For instance, a check on multiple fields for uniqueness in the database can be handled this way. The checkwith class must extend Check. An example will make it more clear
Continue reading “Validations for the Play Framework”

Playframework: Comparing flash parameters for lookup tables

After working with play a bit more I ran into an issue with the flash parameters. If you validate some input form, and there are errors, you can store the previously filled parameters in the flash scope. After that you can re-populate the content of the form again with the flash parameters. However if you have a selection with a lookup table, this will most of the times fail.

Here is a bit of code to explain this situation in more detail. In the html there is a list of entities available:

<select name="orderline.id" id="orderline_id">
  <option value="">Select one
  #{list items: orderlines, as: 'orderline'}
    <option value='${orderline.id}' #{if flash['orderline.id'] != null && flash['orderline.id'] == orderline.id}selected="selected">${orderline.name}
  #{/list}
</select>

Continue reading “Playframework: Comparing flash parameters for lookup tables”