On 5/2/07, Dan Nicolici <[EMAIL PROTECTED]> wrote:
Hi, Nathan!Thanks for the reply! I tried to make this work but I couldn't! Finally I came up with a workaround: I removed the velocity tools archives and went back to velocity-1.4.jar. I changed my servlets to subclass VelocityServlet (which is deprecated in the tools archive) and I used the FileResourceManager. In the servlets I overrode the loadCongifuration() method and I dinamically found the path to the templates folder (this is the whole idea behind the webapp loader since it does find the templates folder relative to the webapp path) with the getRealPath("/") method. I know this ugly, but it works. I would still like to know the answer to why it behaves like I wrote before with the VelocityViewServlet.
i'm glad you got things working. i'm afraid i probably won't be able to help you figure out what went wrong with the previous approach without seeing enough more of your code to duplicate your setup and try and get the same behavior. if you are interested in that, feel free to send your servlet subclass either to the list or directly to me. so you know, you can use the FileResourceLoader with the VelocityViewServlet, if you want to try a mix of your two approaches so far that does not require using the deprecated VelocityServlet.
Nathan Bubna wrote: > On 5/2/07, Dan Nicolici <[EMAIL PROTECTED]> wrote: >> Hi, all! >> >> I'm using VelocityViewServlet in my webapp and I came across a weird >> problem. Every time I open a new browser window and call my webapp URL, >> the variables from my .vm are shown instead of the desired content (like >> $varname). This only happens the on first access on a new browser >> window. After I hit refresh in the browser everything is ok (I get the >> desired content). Then, if I open a new instance of the browser, the >> same thing happens all over again (the webserver is not shutdown between >> the two actions). > > That's odd. What do your servlet logs say on the first hit? (and > perhaps on the second also)? On the first hit it says it cannot find a velocity file needed (someFile.vm) which of course is written by me. On the hits that follow, this doesn't happen.
weird. at least i understand why you thought it was a resource loader issue now. :) that wasn't clear before. any chance you can share the actual log output from servlet startup through the second request? it might help me know what's going on.
> >> I am using Tomcat 5.5. The servlet is declared in the web.xml like this: >> >> <servlet> >> <servlet-name>MyServlet</servlet-name> >> <servlet-class> >> package.UsersServlet >> </servlet-class> > > i presume this is a subclass of VelocityViewServlet? Correct! ...my mistake for leaving it out > >> <init-param> >> <param-name>org.apache.velocity.properties</param-name> >> <param-value>/WEB-INF/velocity.properties</param-value> >> </init-param> >> </servlet> >> >> <servlet-mapping> >> <servlet-name>MyServlet</servlet-name> >> <url-pattern>/index.html</url-pattern> >> </servlet-mapping> >> >> velocity.properties looks like this: >> >> resource.loader = webapp >> webapp.resource.loader.class = >> org.apache.velocity.tools.view.servlet.WebappLoader >> webapp.resource.loader.path = /templates >> # Set cache to true for production >> webapp.resource.loader.cache = false >> webapp.resource.loader.modificationCheckInterval = 60 >> velocimacro.library = myMacro.vm >> >> Can you please help me in getting the right content from the first page >> access? What am I doing wrong (cause I must be doing something wrong)? > > it's hard to tell with the information given. you can always try > comparing your application to the "simple" example app that comes with > VelocityTools and see where things are different. i can tell you that > this is not llikely to be a problem with the resource loader. it > seems like either your context is not populated on first request, or > else the template is being processed (if at all) by something besides > your VelocityViewServlet subclass. > > also, what version of VelocityTools are you using? (probably not > relevant, but i'm curious.) Velocity tools 1.3 > >> --------------------------------------------------------------------- >> To unsubscribe, e-mail: [EMAIL PROTECTED] >> For additional commands, e-mail: [EMAIL PROTECTED] >> >> > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > > > --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
