Announcement Announcement Module
Collapse
No announcement yet.
How I can find out the cause of the command object ... Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • How I can find out the cause of the command object ...

    I run into this error while bringing up a form:

    ERROR org.springframework.web.servlet.tags.BindTag.doSta rtTag:71 - Neither Errors instance nor plain target object for bean name 'command' available as request attribute
    javax.servlet.jsp.JspTagException: Neither Errors instance nor plain target object for bean name 'command' available as request attribute

    I think the reason is either the command object isn't initiated properly or the object is not saved as a request attribute. For the information I have, I can't see the neither case. The command object class is instanceable and the command is definited in the servlet.xml file as the following:

    <property name="commandName"><value>articleForm</value></property>
    <property name="commandClass"><value>com.xxx.web.article.New ArticleForm</value></property>

    Any idea on how to find out the cause?

    Thanks very much for any of your inputs in advance.

    v.

  • #2
    In the controller, where you're returning the model and view, have you used errors.getModel() as the basis for the model you're returning?

    After a form has successfully been submitted the redirects to the success view won't contain the command object anymore (unless you're explicitly adding it to the model, using errors.getModel()).

    rgds,
    alef

    Comment


    • #3
      Thanks for your response, Alef.

      The command object is not a model object, but a form object which in terms contains a model object. The all methods of the class are below:

      public AddArticleFormController() {
      // need a session to hold the formBackingObject
      setSessionForm(true);
      }

      protected Map referenceData(HttpServletRequest request)
      throws ServletException {
      logger.debug(""); // called
      Map refData = new HashMap();
      refData.put("categories", cManager.getCategories());
      return refData;
      }

      protected Object formBackingObject(HttpServletRequest request)
      throws Exception {
      logger.debug(""); //called

      User user = (WebAppUtils.getUserSession(request)).getUser();
      if (user == null)
      throw new ServletException("User session unfound");
      return new NewArticleForm(...);
      }

      protected void initBinder(HttpServletRequest request,
      ServletRequestDataBinder binder) throws Exception {
      logger.debug("");
      binder.registerCustomEditor(byte[].class,
      new ByteArrayMultipartFileEditor());
      }

      protected void onBind(HttpServletRequest request, Object command) {
      logger.debug(""); // not called???
      NewArticleForm entryForm = (NewArticleForm) command;
      int typeId = Integer.parseInt(request.getParameter("catId"));
      Article a = entryForm.getArticle();
      a.setCategory((Category) EntityUtils.getById(cManager
      .getCategories(), Category.class, typeId));
      }

      /** Method inserts a new <code>Entry</code>. */
      protected ModelAndView onSubmit(HttpServletRequest request,
      HttpServletResponse response, Object command, BindException errors)
      throws ServletException {

      NewArticleForm entryForm = (NewArticleForm) command;
      Article entry = entryForm.getArticle();
      logger.debug(entry.toString());
      // delegate the insert to the Business layer
      cManager.submitArticle(entry);
      return new ModelAndView(getSuccessView(), "ownerId", entry
      .getPostedBy().getId());
      }

      The related log messages are the followings:

      DEBUG com.xyz.web.article.AddArticleFormController.showN ewForm:305 - Displaying new form
      DEBUG com.xyz.web.article.AddArticleFormController.formB ackingObject:46 -
      DEBUG com.xyz.web.article.AddArticleFormController.initB inder:58 -
      DEBUG com.xyz.web.article.AddArticleFormController.showF orm:476 - Setting form session attribute [com.xyz.web.article.AddArticleFormController.FORM. articleForm] to: com.xyz.web.article.NewArticleForm@2ddc4c
      DEBUG com.xyz.web.article.AddArticleFormController.refer enceData:38 -

      The error occurs during the time of bringing up the form, but not submitting the form. I can't see any method other than the onSubmit where I can insert the errors.getModel() call.

      Comment

      Working...
      X