2

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

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

@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

<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.

3
  • could you check if there indeed exists a request attribute called user when the jsp is rendered? (use <c:out /> for example) Commented May 19, 2011 at 17:47
  • @Bozho: I have a propery private boolean enabled = true;, with a getter method for it, on my User domain object that I am using here as a backing object. When I try to retrieve ${user.enabled} on signUp.jsp it doesnt show anything, so I think there indeed is no 'user' available as a request attribute. And I am not able to understand why? Commented May 19, 2011 at 21:57
  • @Bozho: I was able to get the signUp.jsp displayed to test ${user.enabled} because I had commented out the complete <table> element which had the <form:form> tag inside it. Commented May 19, 2011 at 22:07

1 Answer 1

1

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 :)

Sign up to request clarification or add additional context in comments.

1 Comment

+1 for solving it yourself. Please accept your own answer when you can.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.