Exception with InitBinder – SpringMVC

I’m using InitBinder to validate form submit, it’s working fine until I accessed to another screen and I received this error :


java.lang.IllegalStateException: Invalid target for Validator[com.mypackage.OrdersFormValidator@2882bdab]:

com.mypackage.OrderDashBoardSearch@2f9e7972 at org.springframework.validation.DataBinder.assertValidators(DataBinder.java:542)

at org.springframework.validation.DataBinder.setValidator(DataBinder.java:533)

at com.mhealth.apotikantar.backend.cms.controller.OrderController.initBinder(OrderController.java:135)

Here is my code in controller :


@InitBinder

protected void initBinder(WebDataBinder binder) {

binder.setValidator(ordersFormValidator);

}

How can I prevent this and add InitBinder to only single method ?

Asked on December 14, 2016 in Java.
Add Comment
1 Answer(s)

With InitBinder, you can pass param to restrict some case only

[/crayon]

The value of

can be one of the following

  • The name of a model attribute
  • The name of a request parameter
  • If none of the above apply, then the name of the class can be used, but starting with a small letter. That’s how Spring exposes unnamed attributes to the model.

 

Answered on December 14, 2016.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.