Issue Details (XML | Word | Printable)

Key: SM-25
Type: Bug Bug
Status: Resolved Resolved
Resolution: Fixed
Priority: Major Major
Assignee: Matt Raible
Reporter: Matt Raible
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
Struts Menu

VelocityDisplayer should use a VelocityEngine instance instead of the singleton Velocity

Created: 09/May/06 01:29 AM   Updated: 09/Jan/07 06:07 PM   Resolved: 06/Oct/06 12:37 AM
Component/s: Displayers
Affects Version/s: 2.3
Fix Version/s: 2.4.2

File Attachments: 1. Text File VelocityMenuDisplayer.patch (6 kB)



 Description  « Hide
Copied from SF http://sourceforge.net/tracker/index.php?func=detail&aid=934474&group_id=48726&atid=453974:

the Velocity displayer should use a VelocityEngine
instance instead of the singleton Velocity. Otherwise,
it may conflict with other usage of Velocity in the
application.

-----
Comments

Date: 2004-11-18 06:23
Sender: uded
Logged In: YES
user_id=126964

Really sorry, missed one more:

-122: t = Velocity.getTemplate(template);
+122: t = velocityInstance.getTemplate(template);



Date: 2004-11-18 04:12
Sender: uded
Logged In: YES
user_id=126964

Got one, see below:

Add field:

    /**
     * Velocity instance for running the template against
     */
    private VelocityEngine velocityInstance;


And then:

57+: velocityInstance = new VelocityEngine();

60-: Velocity.setApplicationAttribute(SERVLET_CONTEXT_KEY,
pageContext.getServletContext());
60+:
velocityInstance.setApplicationAttribute(SERVLET_CONTEXT_KEY,
pageContext.getServletContext());

63-: Velocity.setProperty(RuntimeConstants.RESOURCE_LOADER,
"webapp");
64-: Velocity.setProperty("webapp.resource.loader.class",
WebappLoader.class.getName());


63+:
velocityInstance.setProperty(RuntimeConstants.RESOURCE_LOADER,
"webapp");
64+:
velocityInstance.setProperty("webapp.resource.loader.class",
WebappLoader.class.getName());

89-: Velocity.init(props);
89+: velocityInstance.init(props);


Date: 2004-09-21 21:27
Sender: wrschneider99
Logged In: YES
user_id=768885

you're right, it's not a showstopper. So long as
you're
aware that VelocityMenuDisplayer uses the Velocity
singleton, you just need to know who "wins" by
calling
Velocity.init(props) first. If struts-menu wins, you have
to make sure that you have
WEB-INF/classes/velocity.properties and that it includes
whatever the rest of your app needs. If something else
wins, whatever properties that uses have to also include any
templates that struts-menu will use.

I'll have to get back to you with a patch, since I
haven't
had to build it from source yet. :-)


Date: 2004-09-21 16:41
Sender: mraibleProject Admin
Logged In: YES
user_id=226669

I've used the VelocityDisplayer in other applications with
Velocity and everything seemed to work OK. Do you have a
patch for this? I tried creating a VelocityEngine class
variable, using it in the init and displayComponents
methods, but then I kept getting the following error that I
hadn't before:

log4j:ERROR Attempted to append to closed appender named [null].

Sort Order: Ascending order - Click to sort in descending order
Matt Raible added a comment - 02/Jun/06 05:12 AM
Here's a patch that uses VelocityEngine. Please try the JAR from http://static.appfuse.org/struts-menu-2.4.1.jar. Does this fix your issue?