Hi all,
I have reviewed, and attempted to understand, the posts and code around using Binders, via initBinder(), to format form fields with the <spring:bind /> tag for display.
I have SimpleFormController with a CustomCalendarEditor (like the Date) where the getAsText() is invoked for the form display (a GET) and setAsText is used at submit time (a POST). Works fine.
Now, like many posts I've reviewed, I would like to use the binder framework just for "output" formatting purposes in non submit-based controllers. I have an AbstractCommandController derived Controller with the initBinder() method coded, the commandName and commandClass configured properly etc:
CollectionTO is one of those needed wrappers to use bindings over a collection.Code:<bean id="releaseViewActivityController" class="com.myco.ReleaseViewActivityController"> <property name="releaseFindService" ref="releaseFindService" /> <property name="commandName" value="listTO" /> <property name="commandClass" value="com.myco.to.CollectionTO" /> </bean>
When the controller is handle() and initBinders() are straight forward:
The jslt snippet looks like:Code:protected void initBinder(HttpServletRequest request, ServletRequestDataBinder binder) throws Exception { binder.registerCustomEditor(java.util.Calendar.class, new CustomCalendarEditor(ModelConstants.DATE_FORMAT, false)); } protected ModelAndView handle(HttpServletRequest request, HttpServletResponse response, Object command, BindException errors) throws Exception { ... CollectionTO cto = (CollectionTO) command; cto.setData(activeRelease.getActivities()); //sets a collection. return new ModelAndView("release/release-activity", ModelConstants.MODEL, model); }
The problem is the command, named in this case "listTO", is not available to the jstl view page after handle(). If I add this before the return, still no results shown:Code:<c:forEach var="ra" items="${listTO.data}" varStatus="l"> <tr> <td><spring:bind path="listTO.data[${l.index}].performedOn"> <c:out value="${status.value}"/> </spring:bind></td> <td><spring:bind path="listTO.data[${l.index}].detail"> <c:out value="${status.value}"/> </spring:bind></td> </tr> </c:forEach>
If the results are added to the request directly:Code:Map model = errors.getModel(); model.put(this.getCommandName(), cto);
(knowing this is just foolish) The Calendar field "performedOn" is displayed BUT the binder is not invoked.Code:request.setAttribute(this.getCommandName(), cto);
So, for an AbstractCommandController based controller, where/how does the command get onto the request in a fashion where the binders will be invoked? I have traced the code and am just plain lost. Thanks for any direction.


Reply With Quote