Friday, December 17, 2010

[Java] Error: Method getBindStatus threw exception for reference $springMacroRequestContext

Recently, I came across a problem while working on Spring framework and Velocity; the exception appears to be "ERROR [velocity.app.VelocityEngine] Method getBindStatus threw exception for reference $springMacroRequestContext in template <xyz.vm>". Apparently, it seems like velocity was unable to call the macro or unable to bind some variable in the template.

Actually, I used macro to display tree structure, defined on two different velocity templates, both macro have the same name but different variables were bind with respect to each template requirement. This caused the first visited page to be loaded properly, and on visiting next page, the same macro (from the first page) is called at back end, hence was throwing above mentioned exception. The exception occured because JVM was unable to find the variables used in first template macro, while loading the macro in second template with same macro name.

The solution, is quite simple to this problem. To use different macro name in each template, IF it has any variable or form controls specific to that particualar template.

Another useful information: Changes done in velocity macros do not appear until we restart Tomcat. To have macros changes appear on browser without restarting Tomcat, just change the macro name and refresh the browser.

Enjoy working with Velocity templates. :)

No comments:

Post a Comment