Announcement Announcement Module
No announcement yet.
Command binding with an AbstractCommandController Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Command binding with an AbstractCommandController

    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:

    <bean id="releaseViewActivityController"
       <property name="releaseFindService" ref="releaseFindService" />
       <property name="commandName" value="listTO" />
       <property name="commandClass" value="" />
    CollectionTO is one of those needed wrappers to use bindings over a collection.

    When the controller is handle() and initBinders() are straight forward:

    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 jslt snippet looks like:

    <c:forEach var="ra" items="${}" varStatus="l">
          <td><spring:bind path="[${l.index}].performedOn">
            <c:out value="${status.value}"/>
          <td><spring:bind path="[${l.index}].detail">
            <c:out value="${status.value}"/>
    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:

    Map model = errors.getModel();
    model.put(this.getCommandName(), cto);
    If the results are added to the request directly:

    request.setAttribute(this.getCommandName(), cto);
    (knowing this is just foolish) The Calendar field "performedOn" is displayed BUT the binder is not invoked.

    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.