|
View:
New views
6 Messages
—
Rating Filter:
Alert me
|
|
|
Struts2 & Velocity ToolsHello,
I can't get generic-tools working in my Struts2 Config, objects are not instanciate and are render as String in templates. I don't find any information, samples to get this working, it seems so simple to read :), but impossible to make it work for me :( Can you point me my error, a link, an hint, an advice, anything :D ? Thanks ! I use Struts 2, Velocity 1.5, Velocity Tools 1.4 My configs files are: Toolbox.xml -------------- <toolbox> <tool> <key>date</key> <class>org.apache.velocity.tools.generic.DateTool</class> <scope>request</scope> </tool> <tool> <key>alternator</key> <class>org.apache.velocity.tools.generic.AlternatorTool</class> <scope>application</scope> </tool> <tool> <key>list</key> <class>org.apache.velocity.tools.generic.ListTool</class> <scope>application</scope> </tool> </toolbox> -------------- Web.xml -------------- <servlet> <servlet-name>velocity</servlet-name> <servlet-class>org.apache.velocity.tools.view.servlet.VelocityViewServlet</servlet-class> <init-param> <param-name>org.apache.velocity.toolbox</param-name> <param-value>/WEB-INF/toolbox.xml</param-value> </init-param> <init-param> <param-name>org.apache.velocity.properties</param-name> <param-value>/WEB-INF/velocity.properties</param-value> </init-param> <load-on-startup>10</load-on-startup> </servlet> -------------- velocity.properties -------------- runtime.log = velocity.log runtime.log.error.stacktrace = false runtime.log.warn.stacktrace = false runtime.log.info.stacktrace = false runtime.log.invalid.reference = true runtime.log.logsystem.class = org.apache.velocity.runtime.log.Log4JLogSystem runtime.log.logsystem.log4j.pattern=%d - %m%n input.encoding=ISO-8859-1 output.encoding=ISO-8859-1 directive.foreach.counter.name = velocityCount directive.foreach.counter.initial.value = 1 directive.include.output.errormsg.start = <!-- include error : directive.include.output.errormsg.end = see error log --> directive.parse.max.depth = 10 resource.loader = file file.resource.loader.description = Velocity File Resource Loader file.resource.loader.class = org.apache.velocity.runtime.resource.loader.FileResourceLoader file.resource.loader.path = /home/jboss/server/webServer/deploy/webServer.war/views/HTML file.resource.loader.cache = false file.resource.loader.modificationCheckInterval = 2 velocimacro.library = libs.vm velocimacro.permissions.allow.inline = true velocimacro.permissions.allow.inline.to.replace.global = false velocimacro.permissions.allow.inline.local.scope = false velocimacro.context.localscope = false --------------------- |
|
|
Re: Struts2 & Velocity Toolfollowup questions inline below...
On Mon, Sep 1, 2008 at 2:54 AM, emri <cyrilmery@...> wrote: > > Hello, > > I can't get generic-tools working in my Struts2 Config, objects are not > instanciate and are render as String in templates. I don't find any > information, samples to get this working, it seems so simple to read :), but > impossible to make it work for me :( > > Can you point me my error, a link, an hint, an advice, anything :D ? > > Thanks ! > > > I use Struts 2, Velocity 1.5, Velocity Tools 1.4 > > My configs files are: > > Toolbox.xml > -------------- > <toolbox> > <tool> > <key>date</key> > <class>org.apache.velocity.tools.generic.DateTool</class> > <scope>request</scope> > </tool> > <tool> > <key>alternator</key> > <class>org.apache.velocity.tools.generic.AlternatorTool</class> > <scope>application</scope> > </tool> > <tool> > <key>list</key> > <class>org.apache.velocity.tools.generic.ListTool</class> > <scope>application</scope> > </tool> > </toolbox> > -------------- > > > Web.xml > -------------- > <servlet> > <servlet-name>velocity</servlet-name> > > <servlet-class>org.apache.velocity.tools.view.servlet.VelocityViewServlet</servlet-class> > <init-param> > <param-name>org.apache.velocity.toolbox</param-name> > <param-value>/WEB-INF/toolbox.xml</param-value> > </init-param> > <init-param> > <param-name>org.apache.velocity.properties</param-name> > <param-value>/WEB-INF/velocity.properties</param-value> > </init-param> > <load-on-startup>10</load-on-startup> > </servlet> are you sure that it is the VelocityLayoutServlet that is doing the processing of your templates? I believe Struts 2 has their own way of supporting Velocity that doesn't use the VelocityViewServlet. > velocity.properties > -------------- > > runtime.log = velocity.log > > runtime.log.error.stacktrace = false > runtime.log.warn.stacktrace = false > runtime.log.info.stacktrace = false > runtime.log.invalid.reference = true > runtime.log.logsystem.class = org.apache.velocity.runtime.log.Log4JLogSystem > runtime.log.logsystem.log4j.pattern=%d - %m%n > > > input.encoding=ISO-8859-1 > output.encoding=ISO-8859-1 > > > directive.foreach.counter.name = velocityCount > directive.foreach.counter.initial.value = 1 > > directive.include.output.errormsg.start = <!-- include error : > directive.include.output.errormsg.end = see error log --> > > directive.parse.max.depth = 10 > > > resource.loader = file > > file.resource.loader.description = Velocity File Resource Loader > file.resource.loader.class = > org.apache.velocity.runtime.resource.loader.FileResourceLoader > file.resource.loader.path = > /home/jboss/server/webServer/deploy/webServer.war/views/HTML > file.resource.loader.cache = false > file.resource.loader.modificationCheckInterval = 2 i'm fairly skeptical that this works. you can't typically address files within a war like this. you could just use the default "webapp" resource loader that the VelocityViewServlet provides. i think you just need to remove the file.resource.loader properties above and add this one: webapp.resource.loader.path = /view/HTML > > velocimacro.library = pz_const.vm, pz_libs.vm > > velocimacro.permissions.allow.inline = true > velocimacro.permissions.allow.inline.to.replace.global = false > velocimacro.permissions.allow.inline.local.scope = false > > velocimacro.context.localscope = false > --------------------- > -- > View this message in context: http://www.nabble.com/Struts2---Velocity-Tools-tp19251905p19251905.html > Sent from the Velocity - User mailing list archive at Nabble.com. > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: user-unsubscribe@... > For additional commands, e-mail: user-help@... > > --------------------------------------------------------------------- To unsubscribe, e-mail: user-unsubscribe@... For additional commands, e-mail: user-help@... |
|
|
Re: Struts2 & Velocity ToolThank for your help :)
With some research i managed to understand a bit more what's happening. You are right that the VelocityViewServlet wasn't used here. Struts2 have his own velocity config. So i added in my struts.xml file : struts.xml ---------------- <constant name="struts.velocity.toolboxlocation" value="WEB-INF/toolbox.xml" /> <constant name="struts.velocity.configfile" value="WEB-INF/velocity.properties" /> -------------- Now everything seems to load correctly. About the loader path, i work for me since I'm not using standard web archive. My war is just a folder with the .war extension, that allow jboss to deploy its content on boot. But i recognize it must not be a common way to go :p So now i understand how my templates are rendered using struts2 velocity's engine, but I'm still getting an error when calling any url. here's the stack trace : ---------------------------------- java.lang.NoSuchMethodError: org.apache.velocity.tools.view.context.ChainedContext.<init>(Lorg/apache/velocity/context/Context;Ljavax/servlet/http/HttpServletRequest;Ljavax/servlet/http/HttpServletResponse;Ljavax/servlet/ServletContext;)V org.apache.struts2.views.velocity.VelocityManager.createContext(VelocityManager.java:193) org.apache.struts2.dispatcher.VelocityResult.createContext(VelocityResult.java:235) org.apache.struts2.dispatcher.VelocityResult.doExecute(VelocityResult.java:152) org.apache.struts2.dispatcher.StrutsResultSupport.execute(StrutsResultSupport.java:178) com.opensymphony.xwork2.DefaultActionInvocation.executeResult(DefaultActionInvocation.java:348) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:253) ... -------------------- I found that this constructor has been removed since velocity tools 1.3... Do i need to use an older version (< 1.3) with struts2, or is there any way to work around this with current 1.4 ? Thanx ;-)
|
|
|
Re: Struts2 & Velocity ToolI managed to get it working using velocity tools 1.2. This bug is coming from the org.apache.struts2.views.velocity.VelocityManager class that must not be up to date with velocity changes. I'm heading toward struts forums to try solve this.
(Continued here : https://issues.apache.org/struts/browse/WW-2796 ) Thank for your help :)
|
|
|
Re: Struts2 & Velocity TooYeah, the Struts people are apparently not keeping up with changes. :(
That particular constructor was deprecated even in VelocityTools 1.2. It looks like they are still imagining that Tools 1.1 is standard. It's been a quite a few years since that was true. Thanks for filing the bug with them. On Thu, Sep 4, 2008 at 7:21 AM, emri <cyrilmery@...> wrote: > > I managed to get it working using velocity tools 1.2. This bug is coming from > the org.apache.struts2.views.velocity.VelocityManager class that must not be > up to date with velocity changes. I'm heading toward struts forums to try > solve this. > > (Continued here : https://issues.apache.org/struts/browse/WW-2796 ) > > Thank for your help :) > > > Nathan Bubna wrote: >> >> followup questions inline below... >> >> On Mon, Sep 1, 2008 at 2:54 AM, emri <cyrilmery@...> wrote: >>> >>> Hello, >>> >>> I can't get generic-tools working in my Struts2 Config, objects are not >>> instanciate and are render as String in templates. I don't find any >>> information, samples to get this working, it seems so simple to read :), >>> but >>> impossible to make it work for me :( >>> >>> Can you point me my error, a link, an hint, an advice, anything :D ? >>> >>> Thanks ! >>> >>> >>> I use Struts 2, Velocity 1.5, Velocity Tools 1.4 >>> >>> My configs files are: >>> >>> Toolbox.xml >>> -------------- >>> <toolbox> >>> <tool> >>> <key>date</key> >>> <class>org.apache.velocity.tools.generic.DateTool</class> >>> <scope>request</scope> >>> </tool> >>> <tool> >>> <key>alternator</key> >>> >>> <class>org.apache.velocity.tools.generic.AlternatorTool</class> >>> <scope>application</scope> >>> </tool> >>> <tool> >>> <key>list</key> >>> <class>org.apache.velocity.tools.generic.ListTool</class> >>> <scope>application</scope> >>> </tool> >>> </toolbox> >>> -------------- >>> >>> >>> Web.xml >>> -------------- >>> <servlet> >>> <servlet-name>velocity</servlet-name> >>> >>> <servlet-class>org.apache.velocity.tools.view.servlet.VelocityViewServlet</servlet-class> >>> <init-param> >>> >>> <param-name>org.apache.velocity.toolbox</param-name> >>> <param-value>/WEB-INF/toolbox.xml</param-value> >>> </init-param> >>> <init-param> >>> <param-name>org.apache.velocity.properties</param-name> >>> <param-value>/WEB-INF/velocity.properties</param-value> >>> </init-param> >>> <load-on-startup>10</load-on-startup> >>> </servlet> >> >> >> are you sure that it is the VelocityLayoutServlet that is doing the >> processing of your templates? I believe Struts 2 has their own way >> of supporting Velocity that doesn't use the VelocityViewServlet. >> >>> velocity.properties >>> -------------- >>> >>> runtime.log = velocity.log >>> >>> runtime.log.error.stacktrace = false >>> runtime.log.warn.stacktrace = false >>> runtime.log.info.stacktrace = false >>> runtime.log.invalid.reference = true >>> runtime.log.logsystem.class = >>> org.apache.velocity.runtime.log.Log4JLogSystem >>> runtime.log.logsystem.log4j.pattern=%d - %m%n >>> >>> >>> input.encoding=ISO-8859-1 >>> output.encoding=ISO-8859-1 >>> >>> >>> directive.foreach.counter.name = velocityCount >>> directive.foreach.counter.initial.value = 1 >>> >>> directive.include.output.errormsg.start = <!-- include error : >>> directive.include.output.errormsg.end = see error log --> >>> >>> directive.parse.max.depth = 10 >>> >>> >>> resource.loader = file >>> >>> file.resource.loader.description = Velocity File Resource Loader >>> file.resource.loader.class = >>> org.apache.velocity.runtime.resource.loader.FileResourceLoader >>> file.resource.loader.path = >>> /home/jboss/server/webServer/deploy/webServer.war/views/HTML >>> file.resource.loader.cache = false >>> file.resource.loader.modificationCheckInterval = 2 >> >> i'm fairly skeptical that this works. you can't typically address >> files within a war like this. you could just use the default >> "webapp" resource loader that the VelocityViewServlet provides. i >> think you just need to remove the file.resource.loader properties >> above and add this one: >> >> webapp.resource.loader.path = /view/HTML >> >>> >>> velocimacro.library = pz_const.vm, pz_libs.vm >>> >>> velocimacro.permissions.allow.inline = true >>> velocimacro.permissions.allow.inline.to.replace.global = false >>> velocimacro.permissions.allow.inline.local.scope = false >>> >>> velocimacro.context.localscope = false >>> --------------------- >>> -- >>> View this message in context: >>> http://www.nabble.com/Struts2---Velocity-Tools-tp19251905p19251905.html >>> Sent from the Velocity - User mailing list archive at Nabble.com. >>> >>> >>> --------------------------------------------------------------------- >>> To unsubscribe, e-mail: user-unsubscribe@... >> >>> For additional commands, e-mail: user-help@... >>> >>> >> >> --------------------------------------------------------------------- >> To unsubscribe, e-mail: user-unsubscribe@... >> For additional commands, e-mail: user-help@... >> >> >> > > > > -- > View this message in context: http://www.nabble.com/Struts2---Velocity-Tools-tp19251905p19309167.html > Sent from the Velocity - User mailing list archive at Nabble.com. > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: user-unsubscribe@... > For additional commands, e-mail: user-help@... > > --------------------------------------------------------------------- To unsubscribe, e-mail: user-unsubscribe@... For additional commands, e-mail: user-help@... |
|
|
[FIXED] Struts2 & Velocity Tool 1.4 - deprecated constructor ChainedContextHi,
I managed to get it working with velocity-tools-1.4 : I subclassed the VelocityManager class, overridden the createContextMethod, and replaced the deprecated constructor by the new one : MyVelocityManager.java : -------------------------------------------------------------------------------------- import java.util.Iterator; import java.util.Map; import javax.servlet.ServletContext; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.log4j.Logger; import org.apache.struts2.ServletActionContext; import org.apache.struts2.util.VelocityStrutsUtil; import org.apache.struts2.views.jsp.ui.OgnlTool; import org.apache.struts2.views.util.ContextUtil; import org.apache.struts2.views.velocity.StrutsVelocityContext; import org.apache.struts2.views.velocity.VelocityManager; import org.apache.velocity.VelocityContext; import org.apache.velocity.context.Context; import org.apache.velocity.tools.view.context.ChainedContext; import com.opensymphony.xwork2.util.ValueStack; public class MyVelocityManager extends VelocityManager { private static final Logger LOG = Logger.getLogger(MyVelocityManager.class); public Context createContext(ValueStack stack, HttpServletRequest req, HttpServletResponse res) { VelocityContext[] chainedContexts = prepareChainedContexts(req, res, stack.getContext()); StrutsVelocityContext context = new StrutsVelocityContext(chainedContexts, stack); Map standardMap = ContextUtil.getStandardContext(stack, req, res); for (Iterator iterator = standardMap.entrySet().iterator(); iterator.hasNext();) { Map.Entry entry = (Map.Entry) iterator.next(); context.put((String) entry.getKey(), entry.getValue()); } context.put(STRUTS, new VelocityStrutsUtil(getVelocityEngine(), context, stack, req, res)); ServletContext ctx = null; try { ctx = ServletActionContext.getServletContext(); } catch (NullPointerException npe) { // in case this was used outside the lifecycle of struts servlet LOG.debug("internal toolbox context ignored"); } if (toolboxManager != null && ctx != null) { // here is the new constructor : ChainedContext chained = new ChainedContext(getVelocityEngine(), req, res, ctx); chained.setToolbox(toolboxManager.getToolbox(chained)); return chained; } else { return context; } } } -------------------------------------------------------------------------------------- Now just add this line : struts.xml : -------------------------------------------------------------------------------------- <constant name="struts.velocity.manager.classname" value="your.package.MyVelocityManager" /> -------------------------------------------------------------------------------------- and struts will use your new manager instead of the build in one. Tested with velocity-tools-1.4 only, it seems to work fine. Hope this help ;-)
|
| Free embeddable forum powered by Nabble | Forum Help |