Announcement Announcement Module
Collapse
No announcement yet.
AbstractWizzard Combined With SimpleForm Controller Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • AbstractWizzard Combined With SimpleForm Controller

    I would appreciate your thoughts on using an AbstractWizzardFormController versus a combination of AbstractWizzard and SimpleForm controllers.

    I was set on sub classing the AbstractWizzardFormController until I realized that the controller would be bloated, filled with ugly navigation/button checking code that was outside of the methods defined to handle that sort of thing, and post process actions that would be better handled by GET requests to a SimpleFormController.

    I have the following pages: edit item, add item spreadsheet, edit item spreadsheet, confirm changes.

    Spreadsheet additions and edits are added to respective lists and displayed back to the user on the edit item page as a pending add or edit. All of the built up adds and edits are submitted after confirmation.

    Example:

    On the edit item page (0), when the user edits an existing spreadsheet (2), then decides to add it or cancel their edits, I’d have to do the following:

    Code:
    private Boolean isSpreadsheetCancel(HttpServletRequest request)
    {
      if(getTargetPage(request)!=getCurrentPage(request)) {
        String clicked =
    ServletRequestUtils.getStringParameter(PARAM_TARGET+getTargetPage(request));  
        return (clicked !=null && clicked.equals(BUTTON_CANCEL)); 
      }
      return false;
    }	
    
    protected boolean suppressBinding(HttpServletRequest request)
    {
       return isSpreadsheetCancel(request);
    }
    
    protected boolean suppressValidation(HttpServletRequest request,Object command,BindException errors)
    {
       return isSpreadsheetCancel(request);
    }
    
    protected void postPocessPage(HttpServletRequest request, Object command, Errors errors, int page) throws Exception
    {
    	EditItemForm form = (EditItemForm)command;
    	switch(page) {
    	case 0:   
    	    if(getTargetPage(request)==2) {
                  //get spreadsheet from item’s list		  	       
                  form.setCurrentlyEditedSpreadsheet(theSpreadsheet);			
    	    }
    	    else if(getTargetPage(request)==page) {
    	      //process spreadsheet deletes
       	    }
                break;
            case 2: 
    	    if(!isSpreadsheetCancel(request)) {  
    form.getPendingSpreadsheetEdits().add(form.getCurrentlyEditedSpreadsheet());	
                }
             }
    }
    In case 0, checking for the next page then looking up the target spreadsheet in preparation for the next page is sloppy and could be handled more naturally by a GET to a SimpleFormController where the lookup would be done by formBackingObject().

    Case 2 is even worse, partially because I have to cancel any binding and validation just because I want to cancel the edit or “go back”. Dirty back is not useful here because a cancel and submit will both _target page 0.

    Going back from page 2 can also be better handled by a SimpleFormController. GET to the edit item page; POSTs will no longer be ambiguous.

    Putting the spreadsheet add/edit code it in its own controller would make the code far more succinct.

    The AbstractWizzard subclass would only the edit item and confirm pages.

    Comments anyone?
Working...
X