Announcement Announcement Module
Collapse
No announcement yet.
Spring MVC 3: java.lang.IllegalStateException Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring MVC 3: java.lang.IllegalStateException

    Hi Could someone help me understand what am I doing wrong in the following code due to which I am getting this error:

    Code:
    Caused by: java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name 'user' available as request attribute
        at org.springframework.web.servlet.support.BindStatus.<init>(BindStatus.java:141)
        at org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.getBindStatus(AbstractDataBoundFormElementTag.java:174)
        at org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.getPropertyPath(AbstractDataBoundFormElementTag.java:194)
        at org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.getName(AbstractDataBoundFormElementTag.java:160)
        at org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.autogenerateId(AbstractDataBoundFormElementTag.java:147)
        at org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.resolveId(AbstractDataBoundFormElementTag.java:138)
        at org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.writeDefaultAttributes(AbstractDataBoundFormElementTag.java:122)
        at org.springframework.web.servlet.tags.form.AbstractHtmlElementTag.writeDefaultAttributes(AbstractHtmlElementTag.java:408)
        at org.springframework.web.servlet.tags.form.InputTag.writeTagContent(InputTag.java:140)
        at org.springframework.web.servlet.tags.form.AbstractFormTag.doStartTagInternal(AbstractFormTag.java:102)
        at org.springframework.web.servlet.tags.RequestContextAwareTag.doStartTag(RequestContextAwareTag.java:79)
        at org.apache.jsp.WEB_002dINF.views.signUp_jsp._jspx_meth_form_005finput_005f0(signUp_jsp.java:179)
        at org.apache.jsp.WEB_002dINF.views.signUp_jsp._jspx_meth_form_005fform_005f0(signUp_jsp.java:111)
        at org.apache.jsp.WEB_002dINF.views.signUp_jsp._jspService(signUp_jsp.java:74)
        at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
        at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:374)
        ... 59 more
    UserManagementController.java
    Code:
    @Controller
    public class UserManagementController {	
    	//displays sign up page(GET)
    	@RequestMapping(method=RequestMethod.GET, value="/signUp.html")
    	public ModelAndView signUpForm() {
    		System.out.println("Sign up");
    		return new ModelAndView("/signUp", "user", new User());
    	}
    
    }
    signUp.jsp
    Code:
    <body>
        <h3>Sign up</h3>
        <table>
            <form:form commandName="user" >
                <tr>
                    <td>First name:</td>
                    <td><form:input path="firstName"/></td>
                </tr>
                <tr>
                    <td>Last name:</td>
                    <td><form:input path="lastName"/></td>
                </tr>
                <tr>
                    <td>Username:</td>
                    <td><form:input path="username"/></td>
                </tr>
                <tr>
                    <td>Password:</td>
                    <td><form:input path="password"/></td>
                </tr>
                <tr>
                    <td>Email:</td>
                    <td><form:input path="email"/></td>
                </tr>
                <tr>
                    <td></td>
                    <td><input type="submit" value="Submit"></td>
                </tr>
            </form:form>
        </table>
    </body>
    Could someone help me understand it?

    Thanks.

  • #2
    Hi
    I was mistakenly using the wrong import for ModelAndView.
    I was supposed to use org.springframework.web.servlet.ModelAndView but the one I was mistakenly using was org.springframework.web.portlet.ModelAndView.

    I've got the code working now.

    Thanks

    Comment


    • #3
      I guess you commit errors in your controller. It should be:
      @RequestMapping(value = "/signUp.html", method = RequestMethod.GET)
      public String signUpForm(@ModelAttribute User user){
      System.out.print("Sign up");
      return "yourViewName";
      }

      Comment


      • #4
        Hi presidentrodel
        Yes, I think thats another way to handle the representation of form in spring mvc 2.5 or 3.
        But you could handle it just the way I was I doing it as well. The blunder I commited was that I used the wrong import for ModelAndView.
        I was supposed to use org.springframework.web.servlet.ModelAndView but the one I was mistakenly using was org.springframework.web.portlet.ModelAndView.

        I've got it under control now.
        Thanks for the reply

        Comment


        • #5
          oww. I'm sorry about that. well good to hear that it's ok now. Good luck and Thanks.

          Comment

          Working...
          X