Announcement Announcement Module
Collapse
No announcement yet.
Model Bean re-initialized in JSP Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Model Bean re-initialized in JSP

    Hi,

    I am building a screen using a SimpleFormController and running into a problem where the Model bean I am putting in the ModelAndView is apparently reinitialized in the JSP.

    There are some int and double fields in the bean, which I am using to populate a <table>, but even though I set the bean to have 1 and 1.0 values in the Controller, the tables get populated with 0 and 0.0 respectively.

    the relevant code:

    JSP:
    HTML Code:
    <jsp:useBean id="myBean" class="com.my.myBean" />
    
    ...
    
    <td><c:out value="${myBean.integer1}" /></td>
    Controller:
    Code:
    protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object command, BindException errors)
    {
    ...
    myBean.setInteger1(1);
    ...
    return new ModelAndView(new RedirectView(getSuccessView()), "myBean", myBean);
    }
    Could anyone please suggest why this may be happening?

  • #2
    Code:
    <jsp:useBean id="myBean" class="com.my.myBean" />
    Remove this. Your controller is setting the value for myBean, this code is only overriding it.

    Comment


    • #3
      I removed the line, but now the data is not being populated in the table at all..
      Why would this be happening?

      Comment


      • #4
        You are redirecting to a jsp instead of letting a ViewResolver do its work.

        Comment


        • #5
          I removed the redirect view. Instead I used:

          Code:
          return new ModelAndView("myView", "myBean", myBean);
          And now table is still not being populated...

          Comment


          • #6
            Additionally, when trying to submit the form, I am getting the following exception.

            Code:
            500 Servlet Exception
            
            java.lang.IllegalStateException: Neither Errors instance nor plain target
            object for bean name 'formPOJO' available as request attribute
            Why would that be happening?

            Comment


            • #7
              Resolved

              OK.

              I found a solution to this online and it works:

              In SimpleFormController.onSubmit() I have to add the command object into the MAV under the same name it is configured in the spring config xml.

              Comment


              • #8
                You shouldn't be needing to do that. You should override the formBackingObject for that purpose. I suggest you read the reference guide and take a look at the sample applicaiton.

                Comment

                Working...
                X