Thursday, July 3, 2008

Conditional Form Binding

Form binding is a useful feature in Spring. However I needed to turn on or off form binding depending on certain conditions. Golden question, how to do it...

1. In the controller constructor (or in XML config for DI) call setBindOnNewForm(true);
2. Do NOT call/set setSessionForm(true);
3. Override suppressBinding and return true or false according to your condition. true will suppress form binding.

@Override
protected boolean suppressBinding(HttpServletRequest request){
boolean myCondition = false;
//some checks on myCondition depending on request params
return myCondition ;
}

No comments: