Announcement Announcement Module
Collapse
No announcement yet.
Velocity AbstractSearchTool Spring-aware Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Velocity AbstractSearchTool Spring-aware

    Hi,

    is it possible to make the AbstractSearchTool spring-aware?
    I need to put an dao Object in my searchToolImpl to execute
    a query against the database.
    Do i have to set some options in the toolbox.xml config file or
    should i implement some interface to get it going?

    Regards
    Tim

  • #2
    Making a Velocity Tool Spring-Aware

    It's very possible.

    1) Make sure your tool implements org.apache.velocity.tools.view.tools.ViewTool
    2) Implement ViewTool's public void init(Object obj) method something like so:
    Code:
        public void init(Object obj) {
            logger.debug("initializing " + this.getClass().getName());
    
            ServletContext servletContext = (ServletContext) obj;
            WebApplicationContext ctx = WebApplicationContextUtils
                    .getRequiredWebApplicationContext(servletContext);
            Integer test = (Integer) ctx.getBean("test");
            logger.warn("test from ctx (should be 1):" + test);
    
        }
    3) Define the tool in your Velocity toolbox.xml file - for the example above, define it like:

    Code:
    <tool>
        <key>testtool<key>
        <scope>session</scope>
        <class>your.Tool</class>
      </tool>
    All of the above assumes your tool will have session (or application) scope (as defined in toolbox.xml). If you give it request scope, I believe the object that is passed into the init() method will be of type HttpServletRequest.

    Good luck!
    Jon

    Comment

    Working...
    X