Results 1 to 2 of 2
  1. #1
    d3n1s is offline Member
    Join Date
    Apr 2011
    Posts
    80
    Rep Power
    0

    Default Strange IllegalStateException when bean validation fails

    Hello everyone

    I am building a rather large Spring MVC app, i've done this same exact process with about 20 entity types and i cannot for the life of me figure out why i'm getting this error. I am using javax.validation annotations along with my own custom @Unique annotation and it works great for CRUD operations on ALL my other entity types EXCEPT my Interface class.

    Here are the relevant code snippets :

    VIEW
    XML Code:
    <form:form method="POST" modelAttribute="intface">
                    <form:input type="hidden" path="id" id="id"/>
                    <table>
                        <tr>
                            <td><label for="name">Name: </label> </td>
                            <td><form:input path="name" id="name"/></td>
                            <td><form:errors path="name" cssClass="error"/></td>
                        </tr>
                        <tr>
                            <td><label for="type">Type: </label> </td>
                            <td><form:input path="type" id="type"/></td>
                            <td><form:errors path="type" cssClass="error"/></td>
                        </tr>
                        <tr>
                            <td><label for="ip">IP: </label> </td>
                            <td><form:input path="ip" id="ip"/></td>
                            <td><form:errors path="ip" cssClass="error"/></td>
                        </tr>
                        <tr>
                            <td><label for="port">Port: </label> </td>
                            <td><form:input path="port" id="port"/></td>
                            <td><form:errors path="port" cssClass="error"/></td>
                        </tr>
                        <tr>
                            <td><label for="test">Test: </label> </td>
                            <td><form:checkbox path="test" id="test"/></td>
                            <td><form:errors path="test" cssClass="error"/></td>
                        </tr>
                        <tr>
                            <td colspan="3">
                                <c:choose>
                                    <c:when test="${edit}">
                                        <input type="submit" value="Update Interface"/>
                                    </c:when>
                                    <c:otherwise>
                                        <input type="submit" value="Add Interface"/>
                                    </c:otherwise>
                                </c:choose>
                            </td>
                        </tr>
                    </table>
                </form:form>
    CONTROLLER
    Java Code:
    @RequestMapping(value = {"/newInterface"}, method = RequestMethod.GET)
        public String newInterface(ModelMap model) 
        {
            Interface intface = new Interface();
            model.addAttribute("intface", intface);
            model.addAttribute("edit", false);
            return "interfaceDataAccess";
        }
        
        @RequestMapping(value = {"/newInterface"}, method = RequestMethod.POST)
        public String saveInterface(@Valid Interface intface, BindingResult result, ModelMap model) 
        {
            if (result.hasErrors()) 
            {
                return "interfaceDataAccess";
            }
            interfaceService.saveInterface(intface);
            return "redirect:/interfaces/list";
        }
    ENTITY
    Java Code:
    @Size(min = 1, max = 25, message = "Name must be between 1 and 25 characters long")
        @Unique(entityType = "interface", field = "name", message = "The name needs to be unique!")
        @Column(nullable = false, unique = true, length = 25)
        public String getName() 
        {
            return name;
        }
    
        public void setName(String name) 
        {
            this.name = name;
        }
    The issue is that when i purposely leave a field empty (to test the @Size annotation) i get this exception :

    java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name 'intface' available as request attribute
    org.springframework.web.servlet.support.BindStatus .<init>(BindStatus.java:144)
    org.springframework.web.servlet.tags.form.Abstract DataBoundFormElementTag.getBindStatus(AbstractData BoundFormElementTag.java:168)
    org.springframework.web.servlet.tags.form.Abstract DataBoundFormElementTag.getPropertyPath(AbstractDa taBoundFormElementTag.java:188)
    org.springframework.web.servlet.tags.form.Abstract DataBoundFormElementTag.getName(AbstractDataBoundF ormElementTag.java:154)
    org.springframework.web.servlet.tags.form.Abstract DataBoundFormElementTag.writeDefaultAttributes(Abs tractDataBoundFormElementTag.java:117)
    org.springframework.web.servlet.tags.form.Abstract HtmlElementTag.writeDefaultAttributes(AbstractHtml ElementTag.java:422)
    org.springframework.web.servlet.tags.form.InputTag .writeTagContent(InputTag.java:142)
    org.springframework.web.servlet.tags.form.Abstract FormTag.doStartTagInternal(AbstractFormTag.java:84 )
    org.springframework.web.servlet.tags.RequestContex tAwareTag.doStartTag(RequestContextAwareTag.java:8 0)
    org.apache.jsp.WEB_002dINF.views.interfaceDataAcce ss_jsp._jspx_meth_form_005finput_005f0(interfaceDa taAccess_jsp.java:633)
    org.apache.jsp.WEB_002dINF.views.interfaceDataAcce ss_jsp._jspService(interfaceDataAccess_jsp.java:33 5)
    org.apache.jasper.runtime.HttpJspBase.service(Http JspBase.java:70)
    javax.servlet.http.HttpServlet.service(HttpServlet .java:729)
    org.apache.jasper.servlet.JspServletWrapper.servic e(JspServletWrapper.java:443)
    org.apache.jasper.servlet.JspServlet.serviceJspFil e(JspServlet.java:385)
    org.apache.jasper.servlet.JspServlet.service(JspSe rvlet.java:329)
    javax.servlet.http.HttpServlet.service(HttpServlet .java:729)
    org.apache.tomcat.websocket.server.WsFilter.doFilt er(WsFilter.java:53)
    org.springframework.web.servlet.view.InternalResou rceView.renderMergedOutputModel(InternalResourceVi ew.java:168)
    org.springframework.web.servlet.view.AbstractView. render(AbstractView.java:303)
    org.springframework.web.servlet.DispatcherServlet. render(DispatcherServlet.java:1257)
    org.springframework.web.servlet.DispatcherServlet. processDispatchResult(DispatcherServlet.java:1037)
    org.springframework.web.servlet.DispatcherServlet. doDispatch(DispatcherServlet.java:980)
    org.springframework.web.servlet.DispatcherServlet. doService(DispatcherServlet.java:897)
    org.springframework.web.servlet.FrameworkServlet.p rocessRequest(FrameworkServlet.java:970)
    org.springframework.web.servlet.FrameworkServlet.d oPost(FrameworkServlet.java:872)
    javax.servlet.http.HttpServlet.service(HttpServlet .java:648)
    org.springframework.web.servlet.FrameworkServlet.s ervice(FrameworkServlet.java:846)
    javax.servlet.http.HttpServlet.service(HttpServlet .java:729)
    org.apache.tomcat.websocket.server.WsFilter.doFilt er(WsFilter.java:53)

    I renamed my parameter interface to intface thinking it did not like the word interface but now i'm starting to think it might not like the actual class name Interface. The CRUD operations work perfectly on this entity as long as it does not fail validation. Again, i have like 20 other entities where i do the exact same code and the form correctly returns with the errors populated if one of the fields fails validation. I have attempted to debug this numerous times and the intface variable is NOT NULL before the redirect happens.

    I'm sure it's a stupid error that i'm just not seeing but i cannot find it to save my life.

    Thanks

  2. #2
    d3n1s is offline Member
    Join Date
    Apr 2011
    Posts
    80
    Rep Power
    0

    Default Re: Strange IllegalStateException when bean validation fails

    Any idea anyone? I'm out of ideas for this one. I kinda want to try renaming my Interface class but that is a big undertaking for something that might not even work!

    Thanks

Similar Threads

  1. Replies: 7
    Last Post: 09-26-2012, 01:32 PM
  2. Replies: 0
    Last Post: 07-21-2011, 08:56 AM
  3. Replies: 1
    Last Post: 03-23-2011, 07:55 AM
  4. UREGENT-accessing session bean ok but entity bean
    By parimal in forum Enterprise JavaBeans (EJB)
    Replies: 1
    Last Post: 08-28-2008, 01:34 PM
  5. Replies: 0
    Last Post: 03-30-2008, 10:03 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •