Announcement Announcement Module
Collapse
No announcement yet.
How to disable validation of unbound model properties? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to disable validation of unbound model properties?

    Hi,

    I am using a validator that wrapps a org.springframework.validation.Validator (because I have constraints defined by annotations).

    Code:
    ...
    import org.springframework.validation.Validator;
    
    @Component
    public class ModelValidator {
    
    	@Autowired
    	Validator validator;
    	
    	public void validateSomeState(Model model, ValidationContext context) {
    		MessageContext messages = context.getMessageContext();
    		BindingResult result = new BeanPropertyBindingResult(model, "modelName");
    		MessageBuilder mb = new MessageBuilder();
    		validator.validate(model, result);
    		for (FieldError error : result.getFieldErrors())
    			messages.addMessage(mb.error().source(error.getObjectName() + "." + error.getField()).defaultText(error.getDefaultMessage()).build());
    	}
    ...
    In flow.xml has the model explicitly bound only some properties:

    Code:
    <view-state id="someState" model="model" view="/someView">
    	<binder>
    		<binding property="propertyOne" />
    	</binder>
    ...
    how can I force the validator to validate only bound properties? The ValidationContext has knowledge of the boud properties (at least the default implementation) but I can't find a standard (non-reflective) way to use it. I think this is a common scenario, but didn't find anything usable for me...
    Can anyone help me? Thanks.
Working...
X