[prev in list] [next in list] [prev in thread] [next in thread] 

List:       velocity-user
Subject:    Re: Invalid Reference
From:       "Sven Meier" <sven () meiers ! org>
Date:       2002-01-31 20:06:11
[Download RAW message or body]

Geir,

  I agree with you, that an event handler would be the right solution.

I already tried it with a custom ReferenceInsertionEventHandler,
but in referenceInsert(String, Object) my code can't distinguish an
"invalid" NULL from a "valid" NULL. In either case it gets the same
parameters.

Perhaps the method needs a third boolean parameter, indicating a valid
reference:

   public String referenceInsert(String reference, Object value, boolean
valid);

Or velocity could introduce a new method in the above interface or in a new
interface ReferenceInvalidEventHandler, which gets called in case of a
invalid reference:

  public String referenceInvalid(String reference);

This way my code in referenceInsert(..) could safely assume that a NULL is
"valid" and exchange it with "" or "<YO THIS IS A NULL>".

What do you think?

Sven


----- Original Message -----
From: Geir Magnusson Jr. <geirm@optonline.net>
To: <velocity-user@jakarta.apache.org>
Sent: Wednesday, January 30, 2002 8:13 PM
Subject: Re: Invalid Reference


> On 1/30/02 2:06 PM, "Sven Meier" <sven@meiers.org> wrote:
>
> > Hi,
> >
> > I'm using Velocity successfully in a standalone application for
generating
> > documents with RTF-templates.
>
> Cool!
>
> > What I like most about Velocity is its one-fits-all solution for all
sorts
> > of templates - Mail, Webpages, ... and documents, too.
> >
>
> "General-Purpose Template Engine"
>
> > But I have the question regarding invalid references. Suppose I have the
> > following class:
> >
> > public class Person {
> >   private String name;
> >   public String getName() {
> >     return name;
> >   }
> > }
> >
> > There are three conditions where Velocity will complain about an invalid
> > reference:
> >
> > - Using $person in the template without a person being stored in the
context
> > - Calling $person.Surname (obviously the wrong property) with a person
> > stored under "person" in the context
> > - Calling $person.name with a person with a NULL name.
> >
> > In my opinion the third case isn't an invalid reference:
> > If I want to avoid the insertion of "$person.name" in the output of the
> > template I have to use silent notation, e.g. $!person.name. But now the
> > designer of the document won't get a feedback anymore if he makes an
error
> > and writes "$!person.surname".
>
> Indeed.  Valid point.
>
> > In JSPs NULL values are rendered as "" and I would like to have a
similar
> > output for the third condition above.
> >
> > Is this possible with velocity or should I post a FEATURE-REQUEST to the
> > developer list?
>
> It's possible.  The solution will not be to have it magically become a "",
> but rather we should offer a way to do it with an event handler - so you
can
> override null values with anything you want - like "" for production or
>
> <YO THIS IS A NULL>
>
> For debugging...
>
> Would that work for you?
>
>
> > Sven Meier
> >
> >
> >
> > --
> > To unsubscribe, e-mail:
> > <mailto:velocity-user-unsubscribe@jakarta.apache.org>
> > For additional commands, e-mail:
> > <mailto:velocity-user-help@jakarta.apache.org>
> >
>
> --
> Geir Magnusson Jr.                                     geirm@optonline.net
> System and Software Consulting
> Java : the speed of Smalltalk with the simple elegance of C++...
>
>
> --
> To unsubscribe, e-mail:
<mailto:velocity-user-unsubscribe@jakarta.apache.org>
> For additional commands, e-mail:
<mailto:velocity-user-help@jakarta.apache.org>
>
>



--
To unsubscribe, e-mail:   <mailto:velocity-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:velocity-user-help@jakarta.apache.org>

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic