Announcement Announcement Module
Collapse
No announcement yet.
How to sto stop bind macro showing in Velocity template. Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to sto stop bind macro showing in Velocity template.

    Just starting to use Spring MVC a little more.
    I can bind an input value using Velocity in a page that uses SimpleFormController. However, the page renders in browser showing: "FilePath: #springBind("command.name")

    The template is (copied from Spring docs):
    Code:
    Code:
    <form action="" method="POST"> 
      FilePath&#58; 
      #springBind&#40;"command.name"&#41; 
      <input type="text" 
        name="filePath" 
        value="" /><br> 
      #foreach&#40;$error in $status.errorMessages&#41; <b>$error</b> <br> #end 
      <br> 
      ... 
      <input type="submit" value="submit"/> 
    </form>
    I'm sure its a simple config problem, but I don't see it. Note, if I put the
    code from the samples, 'name="${status.expression}" ', I get Velocity warnings about the expression.

  • #2
    In your configuration for VelocityViewResolver you must set the exposeSpringMacroHelpers property to true for the helper macros to be loaded into the Velocity engine.

    Rob

    Comment


    • #3
      Thanks, but I had that and it doesn't work.

      Code:
          
          
      <bean id="default2HandlerMapping"
          class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
          <property name="mappings">
              <props>
                  <prop key="/file">fileLoadController</prop>
              </props>
          </property>
      </bean>
      
      <bean id="fileLoadController"
          class="some.place.FileLoadController">
          <property name="formView"><value>FileNameForm</value></property>
          
      </bean>
      
      <bean id="viewResolver"
          class="org.springframework.web.servlet.view.velocity.VelocityViewResolver">
          <property name="viewClass">
              <value>org.springframework.web.servlet.view.velocity.VelocityView</value>
              </property>
          <property name="suffix"><value>.html</value></property>
          <property name="exposeSpringMacroHelpers"><value>true</value></property>
          <property name="cache"><value>false</value></property>
      </bean>
      
      <bean id="logFilePathForm"
          class="org.springframework.web.servlet.view.velocity.VelocityView">
          <property name="url"><value>/FileNameForm.html</value>
          </property>
          <property name="velocityEngine"><ref bean="velocityEngine"></ref>
          </property>
      </bean>    
      
      public class FileLoadController extends SimpleFormController &#123;
      	Log log = LogFactory.getLog&#40;FileLoadController.class&#41;;
      	
      	public FileLoadController&#40;&#41; &#123;
      		super&#40;&#41;;
      		setCommandClass&#40;FileCommand.class&#41;;		
      	&#125;
      	
      	protected ModelAndView onSubmit&#40;HttpServletRequest arg0, HttpServletResponse arg1, Object arg2, BindException arg3&#41; throws Exception &#123;
      		log.debug&#40;"onSubmit&#40;&#41; Object=" + arg2.toString&#40;&#41;&#41;;
      		return new ModelAndView&#40;"redirect&#58;main"&#41;;
      	&#125;
      
      &#125;
      
      
      Form load log trace&#58;
        57167 95&#58; 20&#58;56&#58;48,814 DEBUG DefaultListableBeanFactory - Returning cached instance of singleton bean 'fileLoadController'
        57327 21&#58; 20&#58;56&#58;49,164 DEBUG FileLoadController - Displaying new form
        57336 21&#58; 20&#58;56&#58;49,164 DEBUG FileLoadController - Creating new command of class &#91;some.place.FileCommand&#93;
        
      Form submit&#58;
       21&#58;00&#58;08,320 DEBUG FileLoadController - No errors -> processing submit
       21&#58;00&#58;08,320 DEBUG FileLoadController - onSubmit&#40;&#41; Object=some.place.FileCommand@2acc65
       21&#58;00&#58;08,320  WARN VelocityViewResolver - View caching is SWITCHED OFF -- DEVELOPMENT SETTING ONLY&#58; This can severely impair performance

      Comment


      • #4
        I have the same problem

        anyone know how to solve it?

        Comment

        Working...
        X