Announcement Announcement Module
Collapse
No announcement yet.
Velocity, Bind, and IllegalStateException Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Velocity, Bind, and IllegalStateException

    I have an employee lookup form where you input an employee ID and it returns a list of matching employees. This works perfectly well. What I'd like to do is put the same form in the top of the result page, so that the user can check a different employee ID without having to go back a page. I tried to put the form code on top of the result page and bound the field as I had done in the first form. Everything seems to be working fine, until I submit the first form. When it tries to display the second page I get this exception:

    Code:
    [ERROR][org.springframework.ui.velocity.CommonsLoggingLogSystem] - Method getBindStatus threw exception for reference $springMacroRequestContext in template forms/employeeLookupResults.vm at  [4,33]
    [ERROR][org.springframework.web.servlet.FrameworkServlet] - Could not complete request
    org.apache.velocity.exception.MethodInvocationException: Invocation of method 'getBindStatus' in  class org.springframework.web.servlet.support.RequestContext threw exception class java.lang.IllegalStateException : Neither Errors instance nor plain target object for bean name command available as request attribute
    	at org.apache.velocity.runtime.parser.node.ASTMethod.execute(ASTMethod.java:246)
    	at org.apache.velocity.runtime.parser.node.ASTReference.execute(ASTReference.java:175)
    	at org.apache.velocity.runtime.parser.node.ASTReference.value(ASTReference.java:327)
    	at org.apache.velocity.runtime.parser.node.ASTExpression.value(ASTExpression.java:51)
    	at org.apache.velocity.runtime.parser.node.ASTSetDirective.render(ASTSetDirective.java:95)
    	at org.apache.velocity.runtime.parser.node.ASTBlock.render(ASTBlock.java:55)
    	at org.apache.velocity.runtime.parser.node.SimpleNode.render(SimpleNode.java:230)
    	at org.apache.velocity.runtime.parser.node.ASTIfStatement.render(ASTIfStatement.java:89)
    	at org.apache.velocity.runtime.parser.node.SimpleNode.render(SimpleNode.java:230)
    	at org.apache.velocity.runtime.directive.VelocimacroProxy.render(VelocimacroProxy.java:172)
    	at org.apache.velocity.runtime.parser.node.ASTDirective.render(ASTDirective.java:114)
    	at org.apache.velocity.runtime.parser.node.SimpleNode.render(SimpleNode.java:230)
    	at org.apache.velocity.runtime.directive.Parse.render(Parse.java:181)
    	at org.apache.velocity.runtime.parser.node.ASTDirective.render(ASTDirective.java:114)
    	at org.apache.velocity.runtime.parser.node.ASTBlock.render(ASTBlock.java:55)
    	at org.apache.velocity.runtime.parser.node.ASTIfStatement.render(ASTIfStatement.java:70)
    	at org.apache.velocity.runtime.parser.node.SimpleNode.render(SimpleNode.java:230)
    	at org.apache.velocity.Template.merge(Template.java:256)
    	at org.springframework.web.servlet.view.velocity.VelocityView.mergeTemplate(VelocityView.java:553)
    	at org.springframework.web.servlet.view.velocity.VelocityView.doRender(VelocityView.java:500)
    	at org.springframework.web.servlet.view.velocity.VelocityView.renderMergedTemplateModel(VelocityView.java:321)
    	at org.springframework.web.servlet.view.AbstractTemplateView.renderMergedOutputModel(AbstractTemplateView.java:160)
    	at org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:247)
    	at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:784)
    	at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:621)
    	at org.springframework.web.servlet.FrameworkServlet.serviceWrapper(FrameworkServlet.java:368)
    	at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:328)
    	at javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
    	at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
    	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:237)
    	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
    	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:214)
    	at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
    	at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
    	at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:198)
    	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:152)
    	at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
    	at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
    	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:137)
    	at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
    	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:118)
    	at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)
    	at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
    	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
    	at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
    	at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
    	at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:929)
    	at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:160)
    	at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:799)
    	at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:705)
    	at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:577)
    	at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:683)
    	at java.lang.Thread.run(Thread.java:534)
    The form action is calling the URL that is mapped to the controller that will process the request. The form is identical to the one that's working, except that it's located on a page that has data passed to it from the controller. Logic dictates that this would be the reason why it's not working but I'm not sure why that would happen and how to get around it. Does anyone have any suggestions for me?

  • #2
    It seems like Velocity is not able to reach $springMacroRequestContext. Did you include:
    Code:
    <property name="exposeSpringMacroHelpers"><value>true</value></property>
    in your velocity configurtion?

    Comment


    • #3
      I have a parent velocity bean that each specific page is a child of. The parent bean has the exposeSpringMacroHelpers set to true.

      This is the parent bean:
      Code:
        <bean id="parentVelocityView"
              class="org.springframework.web.servlet.view.velocity.VelocityToolboxView"
              abstract="true"
              >
          <property name="url"><value>mainTemplate.vm</value></property>
          <property name="requestContextAttribute"><value>rc</value></property>
          <property name="exposeSpringMacroHelpers"><value>true</value></property>
      	<property name="toolboxConfigLocation"><value>/WEB-INF/toolbox.xml</value></property>
          <property name="attributesMap">
            <map>
              <entry key="title"><value>CCG</value></entry>
              <entry key="banner"><value>menu/tabMenu.vm</value></entry>
              <entry key="rootstylesheet"><value>/styles/main.css</value></entry>
              <entry key="linkstylesheet"><value>/styles/ccg.css</value></entry>
            </map>
          </property>
        </bean>
      and this is the child bean for the specific page I'm having problems with:

      Code:
        <bean id="employeeLookupResultsView" parent="parentVelocityView">
          <property name="requestContextAttribute"><value>rc</value></property>
          <property name="attributes">
            <props>
              <prop key="subtitle">Employee Lookup Results</prop>
              <prop key="bodycontent">forms/employeeLookupResults.vm</prop>
            </props>
          </property>
        </bean>
      The parent view works fine for the other forms I have created, and the other form beans follow this same child bean format.

      Comment


      • #4
        Then I guess you should use $rc instead of $springMacroRequestContext in your velocity pages?

        Comment


        • #5
          Did you mean to use the "long" way to bind instead of springBind? I tried
          Code:
          #set&#40; $status = $rc.getBindStatus&#40;"command.lookupValue"&#41; &#41;
          but it came back with the same exception:
          Code:
          &#91;ERROR&#93;&#91;org.springframework.web.servlet.FrameworkServlet&#93; - Could not complete request
          org.apache.velocity.exception.MethodInvocationException&#58; Invocation of method 'getBindStatus' in  class org.springframework.web.servlet.support.RequestContext threw exception class java.lang.IllegalStateException &#58; Neither Errors instance nor plain target object for bean name command available as request attribute
          
          ...
          The exact same code works fine on the initial form. At first I thought it was because the new form was being displayed in a view determined by the submission of the previous form, but the next page, which you get to via a link on the middle page, does the same thing.

          So far I've had to cheat and put an iframe in each of the two pages but there has to be a more elegant way to do this.

          Thanks for all your help, I'm sorry if i misunderstood your last post.

          Comment


          • #6
            what is the command name in you Controller?

            Comment


            • #7
              in the formBackingObject? It used to be "employeeLookup", but I changed it to "command" and still had the same errors. The commandName property of the bean is omitted so it should be "command" by default, right?

              My original form uses onSubmit to display a view, and that view calls the same form it came from.

              A coworker is trying to use SimpleFormController for multiple forms, however, and is having the same problem.

              Have I thoroughly confused you? I've completely confused myself by now.

              Comment


              • #8
                I've gotten this a bunch of times and it's always been my form backing object not being created properly...either the command name in the bind doesn't match (as an aside, I think the error message should have quotes around the "command" part, since it's not necessarily obvious what the word command means in that context) or for some reason I didn't end up with a backing object.

                Maybe you need "sessionForm" set to true so the backing object survives across requests if you're doing some mildy tricky things?

                I've also run into this because I wanted a completed form submission to go back to the form again, for quick, repeated entries. But once the form is submitted successfully the command object gets removed, AND because it's still a POST formBackingObject didn't get called. So no backing object, and consequently this error. I think I tried to create a new empty form object and explicitly stuff it in the model, but I don't recall that working very well. I think I ended up returning a redirect view instead, which made it a GET, which called formBackingObject.

                Hope some of this rambling helps...

                Comment


                • #9
                  Oh man am I late on this one. Things have gotten a little hectic here. Anyway, you pointed me in the right direction. As soon as I passed the information the form was looking for into the model, it worked perfectly fine. To bind the form field, Spring needs to have that value available to it when creating the page.

                  Thanks a lot for your help.

                  Comment

                  Working...
                  X