that works pretty nicely ... however, is there a reason that the cartridge
doesn't get called if it's in a chained context?
VelocityContext base = new VelocityContext();
base.put("random_global_values",params);
EventCartridge ec = new EventCartridge();
ec.addEventHandler(new MyEventHandler());
ec.attachToContext( base );
VelocityContext final = new VelocityContext(base)
final.put("test",new ArrayList());
if I attach the handler to "final", it works, if i use it as above, it
doesn't get called ...
I do a lot of initialization in my Servlet init() method and I'd prefer not
to have to attach the handler on every handleRequest() call ..
i'm sure the overhead is minimal, but just a suggestion ...
-Dave
> -----Original Message-----
> From: Geir Magnusson Jr. [mailto:[EMAIL PROTECTED]]
> Sent: Monday, May 21, 2001 4:38 PM
> To: [EMAIL PROTECTED]
> Subject: RE: Velocity v1.1-rc1 released
>
>
> >
> > Now, the meat of the matter:
> > As some of my previous posts have indicated, i'm a big fan of
> > the silent
> > notation ... that is, sticking things onto the context and
> > having Velocity
> > just keep its mouth shut if the value doesn't exist/is null/throws an
> > exception/etc ...
> >
> > So, here's what's causing the problem:
> >
> > $supplier.payment_method_list
> > $supplier.payment_method_list.size()
> > $supplier.payment_method_list.get(0)
> > How much wood could a woodchuck chuck?
> >
> > What gets generated from the template merge is:
> > []
> > 0
> > <end of output>
> >
> > When the template tries to call the get(0) method of the zero length
> > ArrayList, Velocity stops parsing the template ... nothing about the
> > woodchuck or the amount of wood that he is chucking ... the
> > following error
> > shows up in the log file:
> >
> > [error] Method get threw exception for reference $supplier in template
> > live/html/checkoutverify.vm at [154,97]
> >
> > I'm content with the message showing up, but it would be nice
> > if Velocity
> > keep pressing on with the rest of the template parsing ... is
> > this desired
> > behavior?
> >
> > I downloaded today's RC1 just to make sure it wasn't a bug
> > that had already
> > been fixed ... but i still have the problem..
>
> It's not a bug - your method is throwing an exception. Bad mojo.
>
> However, you are in luck with v1.1-rc1.
>
> Take a look at the MethodExceptionEventHandling - you can setup an event
> handler to catch exceptions thrown by your methods, substitute a value in
> it's place if you wish, and Vel will continue.
>
> Take a look at the event_example and the EventHandlerTestCase.
>
> geir
>
>