views:

74

answers:

1

I have an app using Spring, JPA (Hibernate) and the Java validation framework (Hibernate Validator). I would like to be able to annotate fields in our domain model that are allowed to contain HTML and have them automatically sanitized at commit time. Anyone know a clever way to do this?

I have tried using the validation framework but this does not support modifying the value of the field at validation time. I could hack things to get something working but am hoping for a cleaner solution.

+1  A: 

You can do it with JPA Entity Listeners annotations:

@PreUpdate

@PrePersist

Anothers solution would be to do it in the own setter.

Manolo Santos
Thanks. I ended up just doing the cleaning in the setter. Not as neat as doing it declaratively with an annotation but real simple.
David Tinker