What we do in our framework is push our tools into the context through a
Spring Proxy which has a MethodInterceptor wrapping the invocation in a
try{
...
} catch (Throwable t)
{
return null
}
block.
Ray
On Thu, 2008-09-11 at 11:43 -0400, Adrian Tarau wrote:
> $! will just avoid printing a NULL value.
>
> Best will be to wrap your objects before place them in the Velocity
> context. Export only those methods that you will used in Velocity and
> catch non-critical exceptions(those that can be converted to a "missing
> value").
>
> Or even better, I would recommend to place in the context only
> POJOs(Plain Java Objects) and not complex/heavy weight objects. Avoid
> lazy initializations(like Hibernate lazy initialized
> collections/objects) because of two reasons : if it fails, it fails
> during rendering(which should not happen, your data should be already
> "collected", ready to be rendered) and if you measure(this matters only
> if you measure it :) ) the page rendering time it will give you wrong
> results(you will blame Velocity for slow rendering or just how the
> template was done).
>
> Prepare your data in the business layer and if nothing fails render your
> data with Velocity to get the result page.
> Is not possible all the time to have all your data ready before
> rendering(for performance reasons), but try to avoid that as much as
> possible.
>
> Nathan Bubna wrote:
> > that won't catch exceptions. you need to use an event handler,
> > particularly the MethodExceptionEventHandler.
> >
> > On Wed, Sep 10, 2008 at 11:44 PM, Manish <[EMAIL PROTECTED]> wrote:
> >
> >> use this -
> >>
> >> my name is: $!o.foo()
> >>
> >> rgds,
> >> - Manish
> >>
> >> ----- Original Message ----- From: "bluejoe" <[EMAIL PROTECTED]>
> >> To: <[email protected]>
> >> Sent: Thursday, September 11, 2008 12:09 PM
> >> Subject: question on Velocity: How to let Velocity keep silent when some
> >> exceptions occur?
> >>
> >>
> >>
> >>> Hi, I am a user of Velocity, now I have a question: How to let Velocity
> >>> keep silent when some exceptions occur?
> >>>
> >>> For example, I wrote codes:
> >>>
> >>> my name is: $o.foo()
> >>>
> >>> In some cases, foo() may throw some exceptions, like NullException, etc.
> >>> It seems that Velocity will throw these exceptions too. But I want
> >>> Velocity
> >>> to regard the statement as:
> >>>
> >>> my name is: <empty>
> >>>
> >>> Is there any way to let Velocity ignore the errors?
> >>>
> >>> Sincerely Yours,
> >>> bluejoe
> >>> 2008-9-11
> >>>
> >>
> >> ---------------------------------------------------------------------
> >> 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]
> >
> >
>
--
Raymond Augé
Software Engineer
Liferay, Inc.
Enterprise. Open Source. For Life.