@Override
  protected Object formBackingObject(HttpServletRequest request) throws Exception {

    log.info("formBackingObject called.");
    MetadataTypeCommand cmd = new MetadataTypeCommand();

    String typeId = request.getParameter("typeId");
    String menuGroup = request.getParameter("menuGroup");
    String categoryId = request.getParameter("categoryId");

    cmd.setCatId(categoryId);

    // used by the UI for to show the side menu
    request.setAttribute("menuGroup", menuGroup);
    request.setAttribute("typeId", typeId);

    if (typeId.equalsIgnoreCase("NEW")) {
      cmd.setMode("NEW");
      return cmd;
    } else {
      MetadataType type = metadataService.getMetadataType(typeId).getMetadataType();
      cmd.setMetadataType(type);
    }
    return cmd;
  }
  @Override
  protected ModelAndView onSubmit(
      HttpServletRequest request,
      HttpServletResponse response,
      Object command,
      BindException errors)
      throws Exception {

    log.info("onSubmit called.");

    MetadataTypeCommand typeCommand = (MetadataTypeCommand) command;
    MetadataType type = typeCommand.getMetadataType();

    log.info("- Mode = " + typeCommand.getMode());

    String btn = request.getParameter("btn");
    if (btn != null && btn.equalsIgnoreCase("Delete")) {
      metadataService.removeMetadataType(type.getMetadataTypeId());
    }

    if ("NEW".equalsIgnoreCase(typeCommand.getMode())) {

      metadataService.addMetadataType(type);
      // associate the new type with a category - USERS, RESOURCES, ETC.

      log.info(
          "Associating type and category ="
              + type.getMetadataTypeId()
              + " - "
              + typeCommand.getCatId());

      metadataService.addTypeToCategory(type.getMetadataTypeId(), typeCommand.getCatId());

    } else {

      metadataService.updateMetdataType(type);
    }

    ModelAndView mav = new ModelAndView(getSuccessView());
    mav.addObject("metadataTypeCmd", typeCommand);

    return mav;
  }