I just tried the new field marker prefix feature of the ServletRequestDataBinder (automatically supplementing request parameters for an unchecked checkbox), and it worked quite well. My solution doesn't seem too smart to me, though:
I set the prefix in the initBinder method of my controller:
and added a hidden parameter to my form:Code:binder.setFieldMarkerPrefix("checkbox_");
Hardcoding the prefix like this is awkward. One possible solution would be to add some sort of global config bean to my application context and retrieve the prefix like this:Code:<input type="hidden" name="checkbox_<jstl:out value="${status.expression}"/>" value="irrelevant"/>... and in my jsp:Code:WebApplicationContext context = (WebApplicationContext)request.getAttribute("org.springframework.web.servlet.DispatcherServlet.CONTEXT"); GlobalConfigBean config = (GlobalConfigBean)context.getBean("config"); binder.setFieldMarkerPrefix(config.getFormPrefix());
Is there any "official" recommendation on how to use the field marker prefix in a more elegant way?Code:<input type="hidden" name="<jstl:out value="${config.formPrefix}"/><jstl:out value="${status.expression}"/>" value="irrelevant"/>
Kind regards


Reply With Quote