You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Petr Toman <Pe...@pinknet.cz> on 2002/01/02 19:24:01 UTC
Re: Problem with variable evaluation in Velocity 1.2
> This works as long you want to WRITE the output, but becomes useless if
> what you want is to resolve to an object reference...Been through that
Exactly.
> public Object referenceEval( Context, Reader ) throws Exception
Would be handy, indeed. Anyway, is there any workaround for my example?
Thanks,
Petr
--
>>> http://dione.zcu.cz/~toman40 - Petr.Toman@pinknet.cz - ICQ=22957959 <<<
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
Re: Problem with variable evaluation in Velocity 1.2
Posted by Petr Toman <Pe...@pinknet.cz>.
> >> public Object referenceEval( Context, Reader ) throws Exception
> >
> > Would be handy, indeed. Anyway, is there any workaround for my example?
>
> I hunted this problem down, as I felt bad for you waiting so long :)
>
> The problem is that between 1.1 and 1.2, we made the internal Velocity
> engine singleton free, and the result is that there is no living
> introspector available (it was a singleton), so that's why ASTMethod
> coughs the hairball.
Thanks a lot! Got it working now. Btw, how can I detect Velocity version? Of
course, I can Class.forName("org.apache.velocity.runtime.RuntimeInstance")
in this case, but it would be useful to have it done in some standard way...
> So... You can hack a solution, but this is a gory hack, IS NOT SUPPORTED,
> AND CAN'T BE GUARANTEED TO WORK TOMORROW, NEXT WEEK, OR EVER :)
Umm, perhaps a silly question: how to recognize the *supported* API? :) How
about dividing javadocs into public/internal APIs (would make it also more
readible)?
Bye, Petr
--
>>> http://dione.zcu.cz/~toman40 - Petr.Toman@pinknet.cz - ICQ=22957959 <<<
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
Re: Problem with variable evaluation in Velocity 1.2
Posted by "Geir Magnusson Jr." <ge...@optonline.net>.
On 1/2/02 1:24 PM, "Petr Toman" <Pe...@pinknet.cz> wrote:
>> This works as long you want to WRITE the output, but becomes useless if
>> what you want is to resolve to an object reference...Been through that
>
> Exactly.
>
>> public Object referenceEval( Context, Reader ) throws Exception
>
> Would be handy, indeed. Anyway, is there any workaround for my example?
>
Well, yes, sort of.
I hunted this problem down, as I felt bad for you waiting so long :)
The problem is that between 1.1 and 1.2, we made the internal Velocity
engine singleton free, and the result is that there is no living
introspector available (it was a singleton), so that's why ASTMethod coughs
the hairball.
So... You can hack a solution, but this is a gory hack, IS NOT SUPPORTED,
AND CAN'T BE GUARANTEED TO WORK TOMORROW, NEXT WEEK, OR EVER :)
This will get you going. Create a RuntimeInstance, init() it, and then use
it when init-ing the node tree. Modulo import statments
RuntimeInstance ri = new RuntimeInstance();
ri.init();
String definition = "$var1.trim().length()";
// init parser
Parser parser = new Parser(new VelocityCharStream(new
StringReader(definition), 0, 0));
SimpleNode node = (SimpleNode) parser.process().jjtGetChild(0);
System.out.println( node );
// init context
InternalContextAdapterImpl context = new
InternalContextAdapterImpl(new VelocityContext());
node.init(context, ri);
// evaluate
context.put("var1", new String(" 123456 "));
System.err.println("1st value = >" + node.execute(null, context) +
"<");
context.put("var1", new String(" 123 "));
System.err.println("2nd value = >" + node.execute(null, context) +
"<");
This will get you going again.
I'll fix things so that you can't init the tree with null for the
RuntimeServices...
This is effectively a bug report, so thanks! :)
Geir
--
Geir Magnusson Jr. geirm@optonline.net
System and Software Consulting
"They that can give up essential liberty to obtain a little temporary safety
deserve neither liberty nor safety." - Benjamin Franklin
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>