We have a SimpleFormController and a formObject which requires a field "id". If the "id" is not given, a MissingServletRequestParameterException should be thrown.
What is the correct workflow?
We did it like this:
Another approach would be to override initBinder() like this:Code:protected void onBindOnNewForm ( HttpServletRequest request, Object command ) throws Exception { CreateForm form = (CreateForm) command; if (form.getId() == null) { throw new MissingServletRequestParameterException("id", "Long"); } }
But this way it won't throw an Exception, so we looked at DefaultBindingErrorProcessor to search for a way to throw an exception if a required field is not given.Code:@Override public void initBinder ( HttpServletRequest request, ServletRequestDataBinder binder ) throws Exception { binder.setRequiredFields(new String[] {"id"}); }
we are a little confused right now, how to choose the "correct" workflow for this scenario, which seems to me very common.
any suggestions? Your help is very appreciated.
kind regards
Janning


Reply With Quote
