snippetjournal

– notes, snippet codes, and my journal

BindException, BindingResult Exception Throw on Error Instead on Controller

leave a comment »

BindException Thrown on bind errors (instead of returning errors to controller method

org.springframework.validation.BindException: org.springframework.validation.BeanPropertyBindingResult: 1 errors

Ok, I really spend more than an hour to resolve this error LOL.😀

Saya mengalami kebingungan karena BindingResult pada spring yang seharus nya melakukan validasi tidak “melempar” hasil exception pada controller, tetapi exception yang di munculkan selalu error pada screen jsp BindException, BindingResult.

Kejadian ini di akibatkan karena pada spring untuk melakukan validasi pada model form harus mengikuti urutan dari model yang bersangkutan, begini contoh nya :

Contoh benar :
@Valid ModelForm modelForm, BindingResult bResult

public String save(@ModelAttribute("modelForm") @Valid ModelForm modelForm, BindingResult bResult, Model model) 
{. . . }

Contoh salah :
@Valid ModelForm modelForm, Model model

public String save(@ModelAttribute("modelForm") @Valid ModelForm modelForm, Model model, BindingResult bResult ) 
{. . . }

reference :
http://forum.spring.io/forum/spring-projects/web/78238-bindexception-thrown-on-bind-errors-instead-of-returning-errors-to-controller-method

Written by snippetjournal

December 18, 2013 at 12:24 pm

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: