Results 1 to 9 of 9

Thread: SimpleFormController and Velocity error

  1. #1

    Default 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. #2
    Join Date
    Aug 2004
    Location
    London, UK
    Posts
    339

    Default Re: SimpleFormController and Velocity error

    Quote 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,
    Darren Davison.
    Public Key: 0xE855B3EA

  3. #3

    Default

    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.

  4. #4

    Default

    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

  5. #5
    Join Date
    Aug 2004
    Location
    London, UK
    Posts
    339

    Default

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

    Regards,
    Darren Davison.
    Public Key: 0xE855B3EA

  6. #6

    Default

    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?

  7. #7
    Join Date
    Aug 2004
    Location
    London, UK
    Posts
    339

    Default

    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?
    Darren Davison.
    Public Key: 0xE855B3EA

  8. #8

    Default

    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>

  9. #9

    Default

    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;

Similar Threads

  1. FreeMarker vs Velocity
    By Martin Kersten in forum Architecture
    Replies: 8
    Last Post: May 30th, 2005, 09:21 AM
  2. Velocity OutOfMemoryError during UnitTests
    By camach in forum Container
    Replies: 2
    Last Post: May 26th, 2005, 05:28 PM
  3. How to get the error message to velocity.
    By todds in forum Security
    Replies: 6
    Last Post: Dec 17th, 2004, 02:59 AM
  4. error loading spring.vm (Velocity)
    By ctaggart in forum Web
    Replies: 2
    Last Post: Oct 25th, 2004, 10:47 PM
  5. Replies: 1
    Last Post: Aug 24th, 2004, 04:37 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
  •