On 12/6/06, Martin Tilsted <[EMAIL PROTECTED]> wrote:
...
> > But I don't understand how VelocityViewServlet, works similary to
> > VelocityServlet. Let my try if I understand VelocityViewServlet correct.
> >
> > 1: I don't have a class for each template. Insted I populate a View with
> > 'tool objects' that are always available for all templates to use.
>
> you don't need a class for each template with the VelocityServlet
> either.  and you don't have to use tools or the toolbox support with
> the VelocityViewServlet if you don't want to.

So I can just use VelocityViewServlet as an (almost) dropin for VelocityServle?

Yeah.  Most of the changes are additions or bug fixes, the overall
design and method signatures are mostly the same.  You should be able
to change your classes to extend VelocityViewServlet and perhaps alter
a few overridden method signatures (mostly with regard to exception
declarations, i believe) and it should work.  if you run into
surprises, let us know and we'll help you straighten it out.

oh, and the request and response are no longer $req and $res, but
$request and $response.

> > 2: My classes don't have to extend VelocityViewServlet
>
> what classes are we talking about?

My current setup is that for each page, I have a class which extend
VelocityServlet. It handles the request, populate the Context and then load the
template for that page. And I like it that way(For my current project atleast)
:}

if it makes you happy, i won't knock it.  are you populating the
context by overriding the createContext() method?  or elsewhere?

> > 4:  It seems like there need to be a way to force a tool to be loaded on a
> give
> > page, even if not used by the template. I don't vant my authorization to
> depend
> > on whenever my SomePage.vm file remember to call the correct method in one
> of my
> > tools. A combination of push and pull would be really cool :}
>
> You can always sub-class the VelocityViewServlet to push data instead
> of always pulling it, but most frameworks support push very well too.

Oh so it is posible. Someone might want to update the documentation at
http://jakarta.apache.org/velocity/tools/view/
Because that description really make it sound VelocityViewServlet is pull only.

Hmm.  Well, i guess that's all we talk about, though it wasn't meant
to ace out the push methodology.  In fact, with the addition of the
chained context (and thus auto-magically including request and session
attributes in the context), doing push is easier and more flexible
with the VelocityViewServlet than it is with the VelocityServlet.

> > Oh, but that was just me trying to understand the pull method. Not my
> current
> > problem. That follow below :}
> >
> >
> > >
> > > Having said that, you need to override the loadConfiguration method to
> > > set Velocity properties.
> >
> > And once I have overridden the loadConfiguration in my MyGallery class what
> am I
> > suposed to do in the overloaded method?
> >
> > I tried to add
> >
> >         protected java.util.Properties
> loadConfiguration(javax.servlet.ServletConfig
> > arg0) throws java.io.IOException, java.io.FileNotFoundException {
> >                 java.util.Properties p=super.loadConfiguration(arg0);
> >
> >
> p.setProperty("directive.foreach.counter.initial.value","0");
> >                 return p;
> >         }
> >
> > But it still start counting with 1.
>
> are you sure this method is being called?

Yes I tried to throw an Error and it was thrown. So it is loaded. But now I have
made velocity read my property file, and that is the best solution :}

> this looks like it should
> work for the VelocityServlet.  of course, using velocity.properties
> should work too (unless you are deploying your application as an
> unexploded war.  VelocityServlet typically fails to load properties in
> such a case because it tries to load it via
> servletContext.getRealPath(file) which doesn't work in all deployment
> scenarios.  this is another area where the VelocityViewServlet is
> superior.

I managed to make it work. The problem was that I was using velocity-dep-1.4.jar
located in apache-tomcat-5.5.17/common/lib
This did for some reason not read my properties file.

So now I have copied velocity-1.4.jar directly to my webapps/twgc/WEB-INF/lib/
directory and now it's working. (twgc is the website)

The really funny thing is that my velocity-1.4.jar depend on
velocity-dep-1.4.jar for some files. But things are working now :}

wonderful!

Martin


---------------------------------------------------------------------
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]

Reply via email to