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

  • SimpleFormController and Velocity error

    I've been getting the following error, no matter what I've tried.

    Code:
    Could not find Errors instance for bean [command] in request:
    I've got this in my controller:

    Code:
    	public ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object command, BindException errors ) throws Exception {
    		User user = (User) command;
    		ModelAndView view;
    		
    		boolean isValidUser = authHandler.isValidUser(user);
    		if(!isValidUser) {
    			errors.reject("invalidLogin", null, "Invalid username and password conbination");
    			view = showForm(request, response, errors);
    		} else {
    			HttpSession session = request.getSession();
    			session.setAttribute("user", user);
    			view = new ModelAndView(getSuccessView(), errors.getModel());
    		}
    		
    		return view;
    	}
    And I've got this in my login.vm file
    Code:
    <html>
    <H2>Login</H2>
    <form method="post" action="editUser.html">
    #springBind&#40;"command"&#41;
    <table>
    </html>
    What am I missing?

  • #2
    Re: SimpleFormController and Velocity error

    Originally posted by davidmitchell
    And I've got this in my login.vm file
    Code:
    <html>
    <H2>Login</H2>
    <form method="post" action="editUser.html">
    #springBind&#40;"command"&#41;
    <table>
    </html>
    What am I missing?
    err, half of your Velocity template from the look of it

    Is your command object actually called "command" or did you set it to something else via the bean property "commandName" on your form controller definition in *-servlet.xml?

    Regards,

    Comment


    • #3
      I haven't changed anything via the *-servlet.xml, or via the setCommandName method.

      I originally had more code in the template, but cut everything out until I just had the one command that threw the exception.

      Comment


      • #4
        After a bit more looking, I've found this in the log:

        Code:
        2004-09-09 11&#58;04&#58;56,119 INFO &#91;org.springframework.web.servlet.view.ResourceBundleViewResolver&#93; - <Cached view 'loginForm_en_US'>
        2004-09-09 11&#58;04&#58;56,126 INFO &#91;org.springframework.ui.context.support.ResourceBundleThemeSource&#93; - <Theme created&#58; name=theme, baseName=theme>
        2004-09-09 11&#58;04&#58;56,159 INFO &#91;org.apache.velocity.app.VelocityEngine&#93; - <ResourceManager &#58; found login.vm with loader org.apache.velocity.runtime.resour
        ce.loader.FileResourceLoader>
        2004-09-09 11&#58;04&#58;56,163 ERROR &#91;org.apache.velocity.app.VelocityEngine&#93; - <Left side &#40;$springHtmlEscape&#41; of '==' operation has null value. If a reference
        , it may not be in the context. Operation not possible. login.vm &#91;line 1, column 33&#93;>
        2004-09-09 11&#58;04&#58;56,163 ERROR &#91;org.apache.velocity.app.VelocityEngine&#93; - <Left side &#40;$springHtmlEscape&#41; of '==' operation has null value. If a reference
        , it may not be in the context. Operation not possible. login.vm &#91;line 1, column 62&#93;>
        2004-09-09 11&#58;04&#58;56,187 ERROR &#91;org.apache.velocity.app.VelocityEngine&#93; - <Method getBindStatus threw exception for reference $springMacroRequestContext
        in template login.vm at  &#91;4,33&#93;>
        Apparently there is a problem resolving the springBind method within the apache template engine. It appears that it is missing some resources or something. Anybody have any ideas on why this could be?

        I'm using a ResourceBundleViewResolver and I've got the following in my view.properties file:
        Code:
        welcomeView.class=org.springframework.web.servlet.view.velocity.VelocityView
        welcomeView.url=index.vm
        welcomeView.exposeSpringMacroHelpers=true
        
        loginView.class=org.springframework.web.servlet.view.velocity.VelocityView
        loginView.url=login.vm
        loginView.exposeSpringMacroHelpers=true

        Comment


        • #5
          what version of Spring are you using? This was fixed after 1.1RC2 (so it should work OK in 1.1 Final).

          Regards,

          Comment


          • #6
            I'm using the released version of 1.1 now, and that particular error is not there anymore, however, I still get the exception, and while running through the log I noticed the following error:

            Code:
            2004-09-13 10&#58;22&#58;50,579 ERROR &#91;org.apache.velocity.app.VelocityEngine&#93; - <ResourceManager &#58; unable to find resource 'VM_global_library.vm' in any resource loader.>
            2004-09-13 10&#58;22&#58;50,579 INFO &#91;org.apache.velocity.app.VelocityEngine&#93; - <Velocimacro &#58; error using  VM library template VM_global_library.vm &#58; org.apache.velocity.exception.ResourceNotFoundException&#58; Unable to find resource 'VM_global_library.vm'>
            Is there some additional configuration that I need to do that I've missed?

            Comment


            • #7
              do you have a reference to such a file in your VelocityConfigurer properties? Velocity should look for a macro file with this name only if another global library is not defined. The Spring Velocity classes define the internal macro file, so I would expect that this error not be output under normal usage.

              Can you post your Velocity config in *-servlet.xml?

              Comment


              • #8
                Here is the velocity related config information

                Code:
                  <bean id="velocityConfig" class="org.springframework.web.servlet.view.velocity.VelocityConfigurer"> 
                    <property name="resourceLoaderPath"><value>/WEB-INF/velocity/</value></property> 
                  </bean> 
                
                  <!-- This bean configures the velocity engine.-->
                  <bean id="velocityEngine" class="org.springframework.ui.velocity.VelocityEngineFactoryBean">
                    <property name="velocityProperties">
                      <props>
                        <prop key="resource.loader">class</prop>
                        <prop key="class.resource.loader.class">org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader</prop>
                      </props>
                    </property>
                  </bean>

                Comment


                • #9
                  I believe I found the problem. It wasn't a configuration problem but rather a problem with the form controller. Having said that, I feel that a class such as SimpleFormController should be useable out of the box without having to do something like this.

                  This could easily be placed into the SimpleFormController, and I've submitted a bug to that effect.

                  Code:
                  public class BaseFormController extends SimpleFormController &#123;
                  
                    protected ModelAndView showForm&#40;HttpServletRequest request, HttpServletResponse response, BindException errors&#41; 
                      throws java.lang.Exception &#123;
                  		
                  		ModelAndView view = super.showForm&#40;request,response, errors&#41;;
                  		view.getModel&#40;&#41;.putAll&#40;errors.getModel&#40;&#41;&#41;;
                  		return view;
                  	&#125;
                  	
                  &#125;

                  Comment

                  Working...
                  X