I am trying to wrap the entity data with some other information such as requestor info. Right now, I have the following code,
public class EntityController {
@Autowired
private EntityValidator entityValidator;
...
@InitBinder("entity")
protected void initBinder(WebDataBinder binder) {
binder.addValidators(entityValidator);
}
}
and my validitor is like
public class EntityValidator implements Validator {
@Override
public boolean supports(Class<?> clz) {
return Entity.class.equals(clz);
}
@Override
public void validate(Object obj, Errors errors) {
...
}
}
For the Object parameter passed into the validate method is the Entity class object now. As I said, I want a customized object with this entity class object wrapped in. Is that possible? If yes, how to do that? Please help. Many thanks.
If I understand correctly, you want the
Entity
instance to be a member of another class (a customized object with this entity class object wrapped in). How about something like this:Which you can implement (the customized object) in a number of ways:
And then use the validator like this:
Notice the
equals
was changed toisAssignableFrom
in thesupports
method. This enables you to pass in a subclass ofEntityHolder
.