The Spring MVC binding mechanism is powerful, but I'm now confronted with a trivial issue that I wonder how to resolve:
User
JPA entity, that is used for the binding and validation as well (i.e. throughout all layers)- "Edit profile" page, that is not supposed to change the password or some other entity properties
Two ways that I can think of:
Using the same object
- use
@InitBinder
to configure a list of disallowed properties - obtain the target user (by id)
- then use a reflection utility (BeanUtils) to copy the submitted object to the target object, but ignore
null
values - i.e. fields that are not submitted
- use
Introduce a new object that has the needed subset of fields, and use
BeanUtils.copyProperties(..)
to merge it to the entity.
Alternatives?