You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@velocity.apache.org by Jeff Schnitzer <je...@infohazard.org> on 2006/08/18 04:22:45 UTC
I dream of a velocity expression custom JSP tag
Short version: I wish for a JSP custom tag that will effectively let me
use Velocity expressions instead of the anemic JSTL expressions.
Long version:
Velocity already has a custom JSP tag that lets me do this:
<vel:velocity>
#if(true) cool velocity stuff #end
</vel:velocity>
However, what I really really want is something that lets me use
velocity expressions the way I would use JSTL expressions. The most
important is this:
<vel:set var="foo" value="${cool.velocity(syntax)}" />
The inability of JSTL expressions to call arbitrary java methods results
in muchhacking and hair pulling. Velocity expressions rock. I want
them :-)
How hard would it be to make a <vel:set> tag? I looked around the APIs
but couldn't find anything helpful.
Thanks,
Jeff
---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-dev-help@jakarta.apache.org
Re: I dream of a velocity expression custom JSP tag
Posted by Nathan Bubna <nb...@gmail.com>.
On 8/23/06, Jeff Schnitzer <je...@infohazard.org> wrote:
> Just catching up, it's a busy week before burning man :-)
>
> I think this is a marvelous idea.
>
> I actually started working on a JSTL-ish set of tags based on the Groovy
> expression language because AFAICT the Groovy expression language is a
> perfect superset of Velocity's. The main reason, though, is that Groovy
> has a nice API that lets me evaluate expressions directly so it's easy.
>
> I'd be perfectly happy with VSTL instead of GSTL... it's just a question
> of a nice API for evaluating expressions.
I just noticed this:
http://jakarta.apache.org/commons/jexl/index.html
if you look at the javadocs, you can see it's not just
Velocity-inspired but is basically a fork of Velocity. Not sure how
best this would fit into a VSTL idea, but it's certainly something we
need to look at.
> Jeff
>
>
> Will Glass-Husain wrote:
> > (And I thought I was being so clever about the Context idea).
> >
> > Another issue is that the emerging VSTL is useful for if's and set's
> > but shares JSTL's wordiness for straight output
> > (e.g. <c:out "${model.property}"/> instead of just $model.property).
> >
> > But mixed in with veltag, you could easily render a block of Velocity
> > in the middle of a page.
> >
> > The more I think about it, the more I like this idea. Be nice for
> > those of us who use JSP and Velocity all the time. I'd think the
> > tasks to build this out into production-ready toolkit would be
> > something like this:
> >
> > * modify Velocity core to support evaluation of expressions
> > * create new VSTL tag library in part that parallels JSTL
> > * add in macro capability (?)
> > * merge in veltag (?)
> > * document, create examples, website, etc.
> >
> > This would be a nice sub-project of a future Velocity TLP. :-)
> >
> > What do you think Jeff? Is this feasible or have we hijacked your
> > idea into something new?
> >
> > WILL
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-dev-help@jakarta.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-dev-help@jakarta.apache.org
Re: I dream of a velocity expression custom JSP tag
Posted by Jeff Schnitzer <je...@infohazard.org>.
Just catching up, it's a busy week before burning man :-)
I think this is a marvelous idea.
I actually started working on a JSTL-ish set of tags based on the Groovy
expression language because AFAICT the Groovy expression language is a
perfect superset of Velocity's. The main reason, though, is that Groovy
has a nice API that lets me evaluate expressions directly so it's easy.
I'd be perfectly happy with VSTL instead of GSTL... it's just a question
of a nice API for evaluating expressions.
Jeff
Will Glass-Husain wrote:
> (And I thought I was being so clever about the Context idea).
>
> Another issue is that the emerging VSTL is useful for if's and set's
> but shares JSTL's wordiness for straight output
> (e.g. <c:out "${model.property}"/> instead of just $model.property).
>
> But mixed in with veltag, you could easily render a block of Velocity
> in the middle of a page.
>
> The more I think about it, the more I like this idea. Be nice for
> those of us who use JSP and Velocity all the time. I'd think the
> tasks to build this out into production-ready toolkit would be
> something like this:
>
> * modify Velocity core to support evaluation of expressions
> * create new VSTL tag library in part that parallels JSTL
> * add in macro capability (?)
> * merge in veltag (?)
> * document, create examples, website, etc.
>
> This would be a nice sub-project of a future Velocity TLP. :-)
>
> What do you think Jeff? Is this feasible or have we hijacked your
> idea into something new?
>
> WILL
---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-dev-help@jakarta.apache.org
Re: I dream of a velocity expression custom JSP tag
Posted by Will Glass-Husain <wg...@forio.com>.
That's interesting. well, we can work on this once there's something
actually built.
On 8/23/06, Serge Knystautas <sk...@gmail.com> wrote:
> One of the strengths of the current JSP specs are .tag files, which is
> a cold fusion idea. I think it would be nice to use a similar
> convention for macros. No idea how that fits though.
>
> --
> Serge Knystautas
> Lokitech >> software . strategy . design >> http://www.lokitech.com
> p. 301.656.5501
> e. sergek@lokitech.com
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-dev-help@jakarta.apache.org
>
>
--
Forio Business Simulations
Will Glass-Husain
wglass@forio.com
www.forio.com
---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-dev-help@jakarta.apache.org
Re: I dream of a velocity expression custom JSP tag
Posted by Will Glass-Husain <wg...@forio.com>.
For me the appeal is the ease of mixing Velocity seamlessly in with
the JSP. (which I do a lot of). Right now it's basically a
one-or-the-other approach.
WILL
On 8/23/06, Robert Koberg <ro...@koberg.com> wrote:
> This whole idea of using <vel:sometag malformed-xml/> seems backward.
>
>
> Serge Knystautas wrote:
> > On 8/22/06, Will Glass-Husain <wg...@forio.com> wrote:
> >> (And I thought I was being so clever about the Context idea).
> >>
> >> Another issue is that the emerging VSTL is useful for if's and set's
> >> but shares JSTL's wordiness for straight output
> >> (e.g. <c:out "${model.property}"/> instead of just $model.property).
> >
> > JSTL lets you do just ${model.property} without the c:out. The
> > advantage to still using c:out at times is that it does XML escaping.
> >
> >> * modify Velocity core to support evaluation of expressions
> >> * create new VSTL tag library in part that parallels JSTL
> >> * add in macro capability (?)
> >> * merge in veltag (?)
> >> * document, create examples, website, etc.
> >
> > One of the strengths of the current JSP specs are .tag files, which is
> > a cold fusion idea. I think it would be nice to use a similar
> > convention for macros. No idea how that fits though.
> >
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-dev-help@jakarta.apache.org
>
>
--
Forio Business Simulations
Will Glass-Husain
wglass@forio.com
www.forio.com
---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-dev-help@jakarta.apache.org
Re: I dream of a velocity expression custom JSP tag
Posted by Will Glass-Husain <wg...@forio.com>.
Technically ${blah} is part of JSP 2.0, right, not JSTL proper, right?
(it's not part of the "Tag Library").
As a side comment I much prefer the auto-escaping. Makes life much
simpler for 99% of the web pages I do.
With Velocity you have to write a ReferenceInsertionEventHandler, and
it's tricky to say "escape these references but not those". In
Velocity 1.5, we'll have a ReferenceInsertionEventHandler built in for
which you can specify which references to escape by pattern matching.
By the way, I think it'd be nice if the nascent VSTL language mirrored
JSTL as much as possible. (e.g. same attributes, just different
expression language) Make it easy for those of us who go back and
forth between the two worlds.
WILL
On 8/24/06, Jeff Schnitzer <je...@infohazard.org> wrote:
> This was a typo... the xml is not malformed. In JSTL you do:
>
> <c:out value="${blah}"/>
>
> This xml-escapes the output. You can also do ${blah} inline, but it
> doesn't xml-escape the output (which is really irritating, imnsho).
>
> Jeff
>
> Robert Koberg wrote:
> > This whole idea of using <vel:sometag malformed-xml/> seems backward.
> >
> >
> > Serge Knystautas wrote:
> >> On 8/22/06, Will Glass-Husain <wg...@forio.com> wrote:
> >>> (And I thought I was being so clever about the Context idea).
> >>>
> >>> Another issue is that the emerging VSTL is useful for if's and set's
> >>> but shares JSTL's wordiness for straight output
> >>> (e.g. <c:out "${model.property}"/> instead of just $model.property).
> >>
> >> JSTL lets you do just ${model.property} without the c:out. The
> >> advantage to still using c:out at times is that it does XML escaping.
> >>
> >>> * modify Velocity core to support evaluation of expressions
> >>> * create new VSTL tag library in part that parallels JSTL
> >>> * add in macro capability (?)
> >>> * merge in veltag (?)
> >>> * document, create examples, website, etc.
> >>
> >> One of the strengths of the current JSP specs are .tag files, which is
> >> a cold fusion idea. I think it would be nice to use a similar
> >> convention for macros. No idea how that fits though.
> >>
> >
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: velocity-dev-help@jakarta.apache.org
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-dev-help@jakarta.apache.org
>
>
--
Forio Business Simulations
Will Glass-Husain
wglass@forio.com
www.forio.com
---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-dev-help@jakarta.apache.org
Re: I dream of a velocity expression custom JSP tag
Posted by Jeff Schnitzer <je...@infohazard.org>.
Jason Pettiss wrote:
> Inline JSP2:
>
> ${fn:escapeXml(blah)}
>
> That does however and in the cases you'd be worried about xml-escapage
> isn't all that irritating. It does mean you have to worry though.
Yes, I know... and I often use my own escapeXml which translates CRs to
<br/>. However, the irritation comes from worrying about the half-dozen
people on my team, including creative-types that might not understand
all the repercussions of missing an escape. One mistake and instant
cross-site-scripting vulnerability. The default of not-escaping was
really dumb in JSP, which is designed to be a web-language (unlike
velocity, which tries to tread some sort of neutral path).
Whoever made this decision in JSP chose the opposite of fail-safe. If
someone makes a mistake now, a non-obvious XSS vulnerability is
introduced. If the case were reverted, a mistake would simply result in
a fairly obvious, non-hazardous display error. Dumb dumb dumb.
Jeff
---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-dev-help@jakarta.apache.org
Re: I dream of a velocity expression custom JSP tag
Posted by Jason Pettiss <ja...@TheCatalis.com>.
Inline JSP2:
${fn:escapeXml(blah)}
That does however and in the cases you'd be worried about xml-escapage
isn't all that irritating. It does mean you have to worry though.
--jason
Jeff Schnitzer wrote:
> This was a typo... the xml is not malformed. In JSTL you do:
>
> <c:out value="${blah}"/>
>
> This xml-escapes the output. You can also do ${blah} inline, but it
> doesn't xml-escape the output (which is really irritating, imnsho).
>
> Jeff
>
> Robert Koberg wrote:
>> This whole idea of using <vel:sometag malformed-xml/> seems backward.
>>
>>
>> Serge Knystautas wrote:
>>> On 8/22/06, Will Glass-Husain <wg...@forio.com> wrote:
>>>> (And I thought I was being so clever about the Context idea).
>>>>
>>>> Another issue is that the emerging VSTL is useful for if's and set's
>>>> but shares JSTL's wordiness for straight output
>>>> (e.g. <c:out "${model.property}"/> instead of just $model.property).
>>>
>>> JSTL lets you do just ${model.property} without the c:out. The
>>> advantage to still using c:out at times is that it does XML escaping.
>>>
>>>> * modify Velocity core to support evaluation of expressions
>>>> * create new VSTL tag library in part that parallels JSTL
>>>> * add in macro capability (?)
>>>> * merge in veltag (?)
>>>> * document, create examples, website, etc.
>>>
>>> One of the strengths of the current JSP specs are .tag files, which is
>>> a cold fusion idea. I think it would be nice to use a similar
>>> convention for macros. No idea how that fits though.
>>>
>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
>> For additional commands, e-mail: velocity-dev-help@jakarta.apache.org
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-dev-help@jakarta.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-dev-help@jakarta.apache.org
Re: I dream of a velocity expression custom JSP tag
Posted by Jeff Schnitzer <je...@infohazard.org>.
This was a typo... the xml is not malformed. In JSTL you do:
<c:out value="${blah}"/>
This xml-escapes the output. You can also do ${blah} inline, but it
doesn't xml-escape the output (which is really irritating, imnsho).
Jeff
Robert Koberg wrote:
> This whole idea of using <vel:sometag malformed-xml/> seems backward.
>
>
> Serge Knystautas wrote:
>> On 8/22/06, Will Glass-Husain <wg...@forio.com> wrote:
>>> (And I thought I was being so clever about the Context idea).
>>>
>>> Another issue is that the emerging VSTL is useful for if's and set's
>>> but shares JSTL's wordiness for straight output
>>> (e.g. <c:out "${model.property}"/> instead of just $model.property).
>>
>> JSTL lets you do just ${model.property} without the c:out. The
>> advantage to still using c:out at times is that it does XML escaping.
>>
>>> * modify Velocity core to support evaluation of expressions
>>> * create new VSTL tag library in part that parallels JSTL
>>> * add in macro capability (?)
>>> * merge in veltag (?)
>>> * document, create examples, website, etc.
>>
>> One of the strengths of the current JSP specs are .tag files, which is
>> a cold fusion idea. I think it would be nice to use a similar
>> convention for macros. No idea how that fits though.
>>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-dev-help@jakarta.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-dev-help@jakarta.apache.org
Re: I dream of a velocity expression custom JSP tag
Posted by Robert Koberg <ro...@koberg.com>.
This whole idea of using <vel:sometag malformed-xml/> seems backward.
Serge Knystautas wrote:
> On 8/22/06, Will Glass-Husain <wg...@forio.com> wrote:
>> (And I thought I was being so clever about the Context idea).
>>
>> Another issue is that the emerging VSTL is useful for if's and set's
>> but shares JSTL's wordiness for straight output
>> (e.g. <c:out "${model.property}"/> instead of just $model.property).
>
> JSTL lets you do just ${model.property} without the c:out. The
> advantage to still using c:out at times is that it does XML escaping.
>
>> * modify Velocity core to support evaluation of expressions
>> * create new VSTL tag library in part that parallels JSTL
>> * add in macro capability (?)
>> * merge in veltag (?)
>> * document, create examples, website, etc.
>
> One of the strengths of the current JSP specs are .tag files, which is
> a cold fusion idea. I think it would be nice to use a similar
> convention for macros. No idea how that fits though.
>
---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-dev-help@jakarta.apache.org
Re: I dream of a velocity expression custom JSP tag
Posted by Serge Knystautas <sk...@gmail.com>.
On 8/22/06, Will Glass-Husain <wg...@forio.com> wrote:
> (And I thought I was being so clever about the Context idea).
>
> Another issue is that the emerging VSTL is useful for if's and set's
> but shares JSTL's wordiness for straight output
> (e.g. <c:out "${model.property}"/> instead of just $model.property).
JSTL lets you do just ${model.property} without the c:out. The
advantage to still using c:out at times is that it does XML escaping.
> * modify Velocity core to support evaluation of expressions
> * create new VSTL tag library in part that parallels JSTL
> * add in macro capability (?)
> * merge in veltag (?)
> * document, create examples, website, etc.
One of the strengths of the current JSP specs are .tag files, which is
a cold fusion idea. I think it would be nice to use a similar
convention for macros. No idea how that fits though.
--
Serge Knystautas
Lokitech >> software . strategy . design >> http://www.lokitech.com
p. 301.656.5501
e. sergek@lokitech.com
---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-dev-help@jakarta.apache.org
Re: I dream of a velocity expression custom JSP tag
Posted by Will Glass-Husain <wg...@forio.com>.
(And I thought I was being so clever about the Context idea).
Another issue is that the emerging VSTL is useful for if's and set's
but shares JSTL's wordiness for straight output
(e.g. <c:out "${model.property}"/> instead of just $model.property).
But mixed in with veltag, you could easily render a block of Velocity
in the middle of a page.
The more I think about it, the more I like this idea. Be nice for
those of us who use JSP and Velocity all the time. I'd think the
tasks to build this out into production-ready toolkit would be
something like this:
* modify Velocity core to support evaluation of expressions
* create new VSTL tag library in part that parallels JSTL
* add in macro capability (?)
* merge in veltag (?)
* document, create examples, website, etc.
This would be a nice sub-project of a future Velocity TLP. :-)
What do you think Jeff? Is this feasible or have we hijacked your
idea into something new?
WILL
On 8/22/06, Nathan Bubna <nb...@gmail.com> wrote:
> On 8/22/06, Will Glass-Husain <wg...@forio.com> wrote:
> > I was driving up this morning (Silicon Valley commute) thinking about
> > this. Maybe we could call it VSTL (Velocity Standard Tag Library)?
>
> :) yeah, that's basically what we're dreaming up. it would be nice.
> JSTL makes JSP much more tolerable, but as a Velocity user, it's still
> frustrating.
>
> > New implementation idea... use a custom Context object that serves as
> > an adapter to the PageContext. This way you wouldn't need to
> > populate a Context ahead of time. Whenever an object is needed, it is
> > just pulled directly from the page/request/session PageContext. (same
> > as JSTL).
>
> Veltag has one of those.
>
> http://svn.apache.org/repos/asf/jakarta/velocity/engine/trunk/experimental/veltag/src/java/org/apache/taglibs/velocity/JSPContext.java
>
> i have an improved version with toolbox support on my local drive.
> it's part of my experimenting for VelocityTools 2.0 (where i'm trying
> to turn Veltag into a VelocityViewTag that parallels the
> VelocityViewServlet in tool support and all that).
>
> It's not all working/compiling yet, but i could check it into a SVN
> whiteboard directory so others can play, if any are interested.
>
> > Similarly, <v:set> would store the object in the PageContext (is
> > request scope the default for JSTL?) with an optional scope parameter
> > to put it in one of the other scopes.
> >
> > We should really make a Wiki page about this...
>
> +1 Go here to create it:
>
> http://wiki.apache.org/jakarta-velocity/VSTL
>
> :)
>
> > WILL
> >
> >
> >
> >
> >
> > On 8/20/06, Will Glass-Husain <wg...@forio.com> wrote:
> > > Incidentally, why stop at <v:set>? I'd also expect to see <v:if>,
> > > <v:choose>/<v:when> (for if/then/else), <v:out>.
> > >
> > > One big advantage of Velocity over JSTL is the ability to easily
> > > create macros. Defining a macro <v:macro> at the top of the page then
> > > using it below would be quite nice. It'd be trickier to implement
> > > though. The above tags could all execute stand-alone VTL, but
> > > <v:macro> would need to have some kind of connection with the tags
> > > later in the page.
> > >
> > > WILL
> > >
> > > On 8/20/06, Will Glass-Husain <wg...@forio.com> wrote:
> > > > Hi Jeff,
> > > >
> > > > Now I get it. If you built a simpler tag that always stored a String
> > > > object this would be easy-- just use Velocity.evaluate as I suggest.
> > > > But you want to evaluate an expression to a resulting object.
> > > >
> > > > Seems to me that you want this to act similar to the Velocity #set.
> > > > You might start by looking at the class
> > > > o.a.v.runtime.parser.node.ASTSetDirective. The key line is:
> > > >
> > > > Object value = right.value(context);
> > > >
> > > > which evaluates the right hand side of the #set expression.
> > > >
> > > > One way of approaching this is to consider that Velocity.evaluate()
> > > > basically ends up calling Node.render() which is a recursive series of
> > > > parser nodes that output to a Writer. You need a similar starting
> > > > point to call Node.value() which will recursively evaluate an
> > > > expression.
> > > >
> > > > Just a few quick thoughts, hope they point you in a useful direction...
> > > >
> > > > WILL
> > > >
> > > > On 8/19/06, Jeff Schnitzer <je...@infohazard.org> wrote:
> > > > > I'm just evaluating Velocity expressions. The result of the expression
> > > > > should be an object, whereas Velocity.evaluate() renders output to a
> > > > > Writer as text. The method I'm looking for would look something like this:
> > > > >
> > > > > public Object evaluate(Context ctx, String expression);
> > > > >
> > > > > For example:
> > > > >
> > > > > ctx.put("now", Calendar.getInstance());
> > > > > TimeZone tz = (TimeZone)evaluate(ctx, "now.timeZone");
> > > > >
> > > > > The Introspector seems to be much, much lower level than this.
> > > > >
> > > > > Thanks,
> > > > > Jeff
> > > > >
> > > > > Will Glass-Husain wrote:
> > > > > > Not sure I get it. Are you making a new expression language or just
> > > > > > evaluating Velocity expressions?
> > > > > >
> > > > > > The introspector is what resolves objects and methods in Velocity.
> > > > > >
> > > > > > WILL
> > > > > >
> > > > > > On 8/19/06, Jeff Schnitzer <je...@infohazard.org> wrote:
> > > > > >> Velocity.evaluate() renders textual output to a Writer. For the
> > > > > >> expression language to work, I need to resolve objects. I can't find
> > > > > >> anything in the javadocs that might give me a hook.
> > > > > >>
> > > > > >> Any suggestions?
> > > > > >>
> > > > > >> I know, I need to wade through the code, but a few starting pointers
> > > > > >> would help.
> > > > > >>
> > > > > >> Thanks,
> > > > > >> Jeff
> > > > > >>
> > > > > >>
> > > > > >> Will Glass-Husain wrote:
> > > > > >> > Wow! As a both a Velocity enthusiast and JSTL junkie that sounds like
> > > > > >> > a really useful tag.
> > > > > >> >
> > > > > >> > It doesn't sound that hard to me. Extract the expression, call
> > > > > >> > Velocity.evaluate, and set the request attribute. I guess you'd have
> > > > > >> > to set up the context with all the beans first.
> > > > > >> >
> > > > > >> > WILL
> > > > > >> >
> > > > > >> >
> > > > > >> > On 8/17/06, Jeff Schnitzer <je...@infohazard.org> wrote:
> > > > > >> >> Short version: I wish for a JSP custom tag that will effectively
> > > > > >> let me
> > > > > >> >> use Velocity expressions instead of the anemic JSTL expressions.
> > > > > >> >>
> > > > > >> >> Long version:
> > > > > >> >>
> > > > > >> >> Velocity already has a custom JSP tag that lets me do this:
> > > > > >> >>
> > > > > >> >> <vel:velocity>
> > > > > >> >> #if(true) cool velocity stuff #end
> > > > > >> >> </vel:velocity>
> > > > > >> >>
> > > > > >> >> However, what I really really want is something that lets me use
> > > > > >> >> velocity expressions the way I would use JSTL expressions. The most
> > > > > >> >> important is this:
> > > > > >> >>
> > > > > >> >> <vel:set var="foo" value="${cool.velocity(syntax)}" />
> > > > > >> >>
> > > > > >> >> The inability of JSTL expressions to call arbitrary java methods
> > > > > >> results
> > > > > >> >> in muchhacking and hair pulling. Velocity expressions rock. I want
> > > > > >> >> them :-)
> > > > > >> >>
> > > > > >> >> How hard would it be to make a <vel:set> tag? I looked around the
> > > > > >> APIs
> > > > > >> >> but couldn't find anything helpful.
> > > > > >> >>
> > > > > >> >> Thanks,
> > > > > >> >> Jeff
> > > > > >> >>
> > > > > >> >> ---------------------------------------------------------------------
> > > > > >> >> To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
> > > > > >> >> For additional commands, e-mail: velocity-dev-help@jakarta.apache.org
> > > > > >> >>
> > > > > >> >>
> > > > > >> >
> > > > > >> >
> > > > > >>
> > > > > >>
> > > > > >> ---------------------------------------------------------------------
> > > > > >> To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
> > > > > >> For additional commands, e-mail: velocity-dev-help@jakarta.apache.org
> > > > > >>
> > > > > >>
> > > > > >
> > > > > >
> > > > >
> > > > >
> > > > > ---------------------------------------------------------------------
> > > > > To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
> > > > > For additional commands, e-mail: velocity-dev-help@jakarta.apache.org
> > > > >
> > > > >
> > > >
> > > >
> > > > --
> > > > Forio Business Simulations
> > > >
> > > > Will Glass-Husain
> > > > wglass@forio.com
> > > > www.forio.com
> > > >
> > >
> > >
> > > --
> > > Forio Business Simulations
> > >
> > > Will Glass-Husain
> > > wglass@forio.com
> > > www.forio.com
> > >
> >
> >
> > --
> > Forio Business Simulations
> >
> > Will Glass-Husain
> > wglass@forio.com
> > www.forio.com
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: velocity-dev-help@jakarta.apache.org
> >
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-dev-help@jakarta.apache.org
>
>
--
Forio Business Simulations
Will Glass-Husain
wglass@forio.com
www.forio.com
---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-dev-help@jakarta.apache.org
Re: I dream of a velocity expression custom JSP tag
Posted by Nathan Bubna <nb...@gmail.com>.
On 8/22/06, Will Glass-Husain <wg...@forio.com> wrote:
> I was driving up this morning (Silicon Valley commute) thinking about
> this. Maybe we could call it VSTL (Velocity Standard Tag Library)?
:) yeah, that's basically what we're dreaming up. it would be nice.
JSTL makes JSP much more tolerable, but as a Velocity user, it's still
frustrating.
> New implementation idea... use a custom Context object that serves as
> an adapter to the PageContext. This way you wouldn't need to
> populate a Context ahead of time. Whenever an object is needed, it is
> just pulled directly from the page/request/session PageContext. (same
> as JSTL).
Veltag has one of those.
http://svn.apache.org/repos/asf/jakarta/velocity/engine/trunk/experimental/veltag/src/java/org/apache/taglibs/velocity/JSPContext.java
i have an improved version with toolbox support on my local drive.
it's part of my experimenting for VelocityTools 2.0 (where i'm trying
to turn Veltag into a VelocityViewTag that parallels the
VelocityViewServlet in tool support and all that).
It's not all working/compiling yet, but i could check it into a SVN
whiteboard directory so others can play, if any are interested.
> Similarly, <v:set> would store the object in the PageContext (is
> request scope the default for JSTL?) with an optional scope parameter
> to put it in one of the other scopes.
>
> We should really make a Wiki page about this...
+1 Go here to create it:
http://wiki.apache.org/jakarta-velocity/VSTL
:)
> WILL
>
>
>
>
>
> On 8/20/06, Will Glass-Husain <wg...@forio.com> wrote:
> > Incidentally, why stop at <v:set>? I'd also expect to see <v:if>,
> > <v:choose>/<v:when> (for if/then/else), <v:out>.
> >
> > One big advantage of Velocity over JSTL is the ability to easily
> > create macros. Defining a macro <v:macro> at the top of the page then
> > using it below would be quite nice. It'd be trickier to implement
> > though. The above tags could all execute stand-alone VTL, but
> > <v:macro> would need to have some kind of connection with the tags
> > later in the page.
> >
> > WILL
> >
> > On 8/20/06, Will Glass-Husain <wg...@forio.com> wrote:
> > > Hi Jeff,
> > >
> > > Now I get it. If you built a simpler tag that always stored a String
> > > object this would be easy-- just use Velocity.evaluate as I suggest.
> > > But you want to evaluate an expression to a resulting object.
> > >
> > > Seems to me that you want this to act similar to the Velocity #set.
> > > You might start by looking at the class
> > > o.a.v.runtime.parser.node.ASTSetDirective. The key line is:
> > >
> > > Object value = right.value(context);
> > >
> > > which evaluates the right hand side of the #set expression.
> > >
> > > One way of approaching this is to consider that Velocity.evaluate()
> > > basically ends up calling Node.render() which is a recursive series of
> > > parser nodes that output to a Writer. You need a similar starting
> > > point to call Node.value() which will recursively evaluate an
> > > expression.
> > >
> > > Just a few quick thoughts, hope they point you in a useful direction...
> > >
> > > WILL
> > >
> > > On 8/19/06, Jeff Schnitzer <je...@infohazard.org> wrote:
> > > > I'm just evaluating Velocity expressions. The result of the expression
> > > > should be an object, whereas Velocity.evaluate() renders output to a
> > > > Writer as text. The method I'm looking for would look something like this:
> > > >
> > > > public Object evaluate(Context ctx, String expression);
> > > >
> > > > For example:
> > > >
> > > > ctx.put("now", Calendar.getInstance());
> > > > TimeZone tz = (TimeZone)evaluate(ctx, "now.timeZone");
> > > >
> > > > The Introspector seems to be much, much lower level than this.
> > > >
> > > > Thanks,
> > > > Jeff
> > > >
> > > > Will Glass-Husain wrote:
> > > > > Not sure I get it. Are you making a new expression language or just
> > > > > evaluating Velocity expressions?
> > > > >
> > > > > The introspector is what resolves objects and methods in Velocity.
> > > > >
> > > > > WILL
> > > > >
> > > > > On 8/19/06, Jeff Schnitzer <je...@infohazard.org> wrote:
> > > > >> Velocity.evaluate() renders textual output to a Writer. For the
> > > > >> expression language to work, I need to resolve objects. I can't find
> > > > >> anything in the javadocs that might give me a hook.
> > > > >>
> > > > >> Any suggestions?
> > > > >>
> > > > >> I know, I need to wade through the code, but a few starting pointers
> > > > >> would help.
> > > > >>
> > > > >> Thanks,
> > > > >> Jeff
> > > > >>
> > > > >>
> > > > >> Will Glass-Husain wrote:
> > > > >> > Wow! As a both a Velocity enthusiast and JSTL junkie that sounds like
> > > > >> > a really useful tag.
> > > > >> >
> > > > >> > It doesn't sound that hard to me. Extract the expression, call
> > > > >> > Velocity.evaluate, and set the request attribute. I guess you'd have
> > > > >> > to set up the context with all the beans first.
> > > > >> >
> > > > >> > WILL
> > > > >> >
> > > > >> >
> > > > >> > On 8/17/06, Jeff Schnitzer <je...@infohazard.org> wrote:
> > > > >> >> Short version: I wish for a JSP custom tag that will effectively
> > > > >> let me
> > > > >> >> use Velocity expressions instead of the anemic JSTL expressions.
> > > > >> >>
> > > > >> >> Long version:
> > > > >> >>
> > > > >> >> Velocity already has a custom JSP tag that lets me do this:
> > > > >> >>
> > > > >> >> <vel:velocity>
> > > > >> >> #if(true) cool velocity stuff #end
> > > > >> >> </vel:velocity>
> > > > >> >>
> > > > >> >> However, what I really really want is something that lets me use
> > > > >> >> velocity expressions the way I would use JSTL expressions. The most
> > > > >> >> important is this:
> > > > >> >>
> > > > >> >> <vel:set var="foo" value="${cool.velocity(syntax)}" />
> > > > >> >>
> > > > >> >> The inability of JSTL expressions to call arbitrary java methods
> > > > >> results
> > > > >> >> in muchhacking and hair pulling. Velocity expressions rock. I want
> > > > >> >> them :-)
> > > > >> >>
> > > > >> >> How hard would it be to make a <vel:set> tag? I looked around the
> > > > >> APIs
> > > > >> >> but couldn't find anything helpful.
> > > > >> >>
> > > > >> >> Thanks,
> > > > >> >> Jeff
> > > > >> >>
> > > > >> >> ---------------------------------------------------------------------
> > > > >> >> To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
> > > > >> >> For additional commands, e-mail: velocity-dev-help@jakarta.apache.org
> > > > >> >>
> > > > >> >>
> > > > >> >
> > > > >> >
> > > > >>
> > > > >>
> > > > >> ---------------------------------------------------------------------
> > > > >> To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
> > > > >> For additional commands, e-mail: velocity-dev-help@jakarta.apache.org
> > > > >>
> > > > >>
> > > > >
> > > > >
> > > >
> > > >
> > > > ---------------------------------------------------------------------
> > > > To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
> > > > For additional commands, e-mail: velocity-dev-help@jakarta.apache.org
> > > >
> > > >
> > >
> > >
> > > --
> > > Forio Business Simulations
> > >
> > > Will Glass-Husain
> > > wglass@forio.com
> > > www.forio.com
> > >
> >
> >
> > --
> > Forio Business Simulations
> >
> > Will Glass-Husain
> > wglass@forio.com
> > www.forio.com
> >
>
>
> --
> Forio Business Simulations
>
> Will Glass-Husain
> wglass@forio.com
> www.forio.com
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-dev-help@jakarta.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-dev-help@jakarta.apache.org
Re: I dream of a velocity expression custom JSP tag
Posted by Will Glass-Husain <wg...@forio.com>.
I was driving up this morning (Silicon Valley commute) thinking about
this. Maybe we could call it VSTL (Velocity Standard Tag Library)?
New implementation idea... use a custom Context object that serves as
an adapter to the PageContext. This way you wouldn't need to
populate a Context ahead of time. Whenever an object is needed, it is
just pulled directly from the page/request/session PageContext. (same
as JSTL).
Similarly, <v:set> would store the object in the PageContext (is
request scope the default for JSTL?) with an optional scope parameter
to put it in one of the other scopes.
We should really make a Wiki page about this...
WILL
On 8/20/06, Will Glass-Husain <wg...@forio.com> wrote:
> Incidentally, why stop at <v:set>? I'd also expect to see <v:if>,
> <v:choose>/<v:when> (for if/then/else), <v:out>.
>
> One big advantage of Velocity over JSTL is the ability to easily
> create macros. Defining a macro <v:macro> at the top of the page then
> using it below would be quite nice. It'd be trickier to implement
> though. The above tags could all execute stand-alone VTL, but
> <v:macro> would need to have some kind of connection with the tags
> later in the page.
>
> WILL
>
> On 8/20/06, Will Glass-Husain <wg...@forio.com> wrote:
> > Hi Jeff,
> >
> > Now I get it. If you built a simpler tag that always stored a String
> > object this would be easy-- just use Velocity.evaluate as I suggest.
> > But you want to evaluate an expression to a resulting object.
> >
> > Seems to me that you want this to act similar to the Velocity #set.
> > You might start by looking at the class
> > o.a.v.runtime.parser.node.ASTSetDirective. The key line is:
> >
> > Object value = right.value(context);
> >
> > which evaluates the right hand side of the #set expression.
> >
> > One way of approaching this is to consider that Velocity.evaluate()
> > basically ends up calling Node.render() which is a recursive series of
> > parser nodes that output to a Writer. You need a similar starting
> > point to call Node.value() which will recursively evaluate an
> > expression.
> >
> > Just a few quick thoughts, hope they point you in a useful direction...
> >
> > WILL
> >
> > On 8/19/06, Jeff Schnitzer <je...@infohazard.org> wrote:
> > > I'm just evaluating Velocity expressions. The result of the expression
> > > should be an object, whereas Velocity.evaluate() renders output to a
> > > Writer as text. The method I'm looking for would look something like this:
> > >
> > > public Object evaluate(Context ctx, String expression);
> > >
> > > For example:
> > >
> > > ctx.put("now", Calendar.getInstance());
> > > TimeZone tz = (TimeZone)evaluate(ctx, "now.timeZone");
> > >
> > > The Introspector seems to be much, much lower level than this.
> > >
> > > Thanks,
> > > Jeff
> > >
> > > Will Glass-Husain wrote:
> > > > Not sure I get it. Are you making a new expression language or just
> > > > evaluating Velocity expressions?
> > > >
> > > > The introspector is what resolves objects and methods in Velocity.
> > > >
> > > > WILL
> > > >
> > > > On 8/19/06, Jeff Schnitzer <je...@infohazard.org> wrote:
> > > >> Velocity.evaluate() renders textual output to a Writer. For the
> > > >> expression language to work, I need to resolve objects. I can't find
> > > >> anything in the javadocs that might give me a hook.
> > > >>
> > > >> Any suggestions?
> > > >>
> > > >> I know, I need to wade through the code, but a few starting pointers
> > > >> would help.
> > > >>
> > > >> Thanks,
> > > >> Jeff
> > > >>
> > > >>
> > > >> Will Glass-Husain wrote:
> > > >> > Wow! As a both a Velocity enthusiast and JSTL junkie that sounds like
> > > >> > a really useful tag.
> > > >> >
> > > >> > It doesn't sound that hard to me. Extract the expression, call
> > > >> > Velocity.evaluate, and set the request attribute. I guess you'd have
> > > >> > to set up the context with all the beans first.
> > > >> >
> > > >> > WILL
> > > >> >
> > > >> >
> > > >> > On 8/17/06, Jeff Schnitzer <je...@infohazard.org> wrote:
> > > >> >> Short version: I wish for a JSP custom tag that will effectively
> > > >> let me
> > > >> >> use Velocity expressions instead of the anemic JSTL expressions.
> > > >> >>
> > > >> >> Long version:
> > > >> >>
> > > >> >> Velocity already has a custom JSP tag that lets me do this:
> > > >> >>
> > > >> >> <vel:velocity>
> > > >> >> #if(true) cool velocity stuff #end
> > > >> >> </vel:velocity>
> > > >> >>
> > > >> >> However, what I really really want is something that lets me use
> > > >> >> velocity expressions the way I would use JSTL expressions. The most
> > > >> >> important is this:
> > > >> >>
> > > >> >> <vel:set var="foo" value="${cool.velocity(syntax)}" />
> > > >> >>
> > > >> >> The inability of JSTL expressions to call arbitrary java methods
> > > >> results
> > > >> >> in muchhacking and hair pulling. Velocity expressions rock. I want
> > > >> >> them :-)
> > > >> >>
> > > >> >> How hard would it be to make a <vel:set> tag? I looked around the
> > > >> APIs
> > > >> >> but couldn't find anything helpful.
> > > >> >>
> > > >> >> Thanks,
> > > >> >> Jeff
> > > >> >>
> > > >> >> ---------------------------------------------------------------------
> > > >> >> To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
> > > >> >> For additional commands, e-mail: velocity-dev-help@jakarta.apache.org
> > > >> >>
> > > >> >>
> > > >> >
> > > >> >
> > > >>
> > > >>
> > > >> ---------------------------------------------------------------------
> > > >> To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
> > > >> For additional commands, e-mail: velocity-dev-help@jakarta.apache.org
> > > >>
> > > >>
> > > >
> > > >
> > >
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
> > > For additional commands, e-mail: velocity-dev-help@jakarta.apache.org
> > >
> > >
> >
> >
> > --
> > Forio Business Simulations
> >
> > Will Glass-Husain
> > wglass@forio.com
> > www.forio.com
> >
>
>
> --
> Forio Business Simulations
>
> Will Glass-Husain
> wglass@forio.com
> www.forio.com
>
--
Forio Business Simulations
Will Glass-Husain
wglass@forio.com
www.forio.com
---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-dev-help@jakarta.apache.org
Re: I dream of a velocity expression custom JSP tag
Posted by Will Glass-Husain <wg...@forio.com>.
Incidentally, why stop at <v:set>? I'd also expect to see <v:if>,
<v:choose>/<v:when> (for if/then/else), <v:out>.
One big advantage of Velocity over JSTL is the ability to easily
create macros. Defining a macro <v:macro> at the top of the page then
using it below would be quite nice. It'd be trickier to implement
though. The above tags could all execute stand-alone VTL, but
<v:macro> would need to have some kind of connection with the tags
later in the page.
WILL
On 8/20/06, Will Glass-Husain <wg...@forio.com> wrote:
> Hi Jeff,
>
> Now I get it. If you built a simpler tag that always stored a String
> object this would be easy-- just use Velocity.evaluate as I suggest.
> But you want to evaluate an expression to a resulting object.
>
> Seems to me that you want this to act similar to the Velocity #set.
> You might start by looking at the class
> o.a.v.runtime.parser.node.ASTSetDirective. The key line is:
>
> Object value = right.value(context);
>
> which evaluates the right hand side of the #set expression.
>
> One way of approaching this is to consider that Velocity.evaluate()
> basically ends up calling Node.render() which is a recursive series of
> parser nodes that output to a Writer. You need a similar starting
> point to call Node.value() which will recursively evaluate an
> expression.
>
> Just a few quick thoughts, hope they point you in a useful direction...
>
> WILL
>
> On 8/19/06, Jeff Schnitzer <je...@infohazard.org> wrote:
> > I'm just evaluating Velocity expressions. The result of the expression
> > should be an object, whereas Velocity.evaluate() renders output to a
> > Writer as text. The method I'm looking for would look something like this:
> >
> > public Object evaluate(Context ctx, String expression);
> >
> > For example:
> >
> > ctx.put("now", Calendar.getInstance());
> > TimeZone tz = (TimeZone)evaluate(ctx, "now.timeZone");
> >
> > The Introspector seems to be much, much lower level than this.
> >
> > Thanks,
> > Jeff
> >
> > Will Glass-Husain wrote:
> > > Not sure I get it. Are you making a new expression language or just
> > > evaluating Velocity expressions?
> > >
> > > The introspector is what resolves objects and methods in Velocity.
> > >
> > > WILL
> > >
> > > On 8/19/06, Jeff Schnitzer <je...@infohazard.org> wrote:
> > >> Velocity.evaluate() renders textual output to a Writer. For the
> > >> expression language to work, I need to resolve objects. I can't find
> > >> anything in the javadocs that might give me a hook.
> > >>
> > >> Any suggestions?
> > >>
> > >> I know, I need to wade through the code, but a few starting pointers
> > >> would help.
> > >>
> > >> Thanks,
> > >> Jeff
> > >>
> > >>
> > >> Will Glass-Husain wrote:
> > >> > Wow! As a both a Velocity enthusiast and JSTL junkie that sounds like
> > >> > a really useful tag.
> > >> >
> > >> > It doesn't sound that hard to me. Extract the expression, call
> > >> > Velocity.evaluate, and set the request attribute. I guess you'd have
> > >> > to set up the context with all the beans first.
> > >> >
> > >> > WILL
> > >> >
> > >> >
> > >> > On 8/17/06, Jeff Schnitzer <je...@infohazard.org> wrote:
> > >> >> Short version: I wish for a JSP custom tag that will effectively
> > >> let me
> > >> >> use Velocity expressions instead of the anemic JSTL expressions.
> > >> >>
> > >> >> Long version:
> > >> >>
> > >> >> Velocity already has a custom JSP tag that lets me do this:
> > >> >>
> > >> >> <vel:velocity>
> > >> >> #if(true) cool velocity stuff #end
> > >> >> </vel:velocity>
> > >> >>
> > >> >> However, what I really really want is something that lets me use
> > >> >> velocity expressions the way I would use JSTL expressions. The most
> > >> >> important is this:
> > >> >>
> > >> >> <vel:set var="foo" value="${cool.velocity(syntax)}" />
> > >> >>
> > >> >> The inability of JSTL expressions to call arbitrary java methods
> > >> results
> > >> >> in muchhacking and hair pulling. Velocity expressions rock. I want
> > >> >> them :-)
> > >> >>
> > >> >> How hard would it be to make a <vel:set> tag? I looked around the
> > >> APIs
> > >> >> but couldn't find anything helpful.
> > >> >>
> > >> >> Thanks,
> > >> >> Jeff
> > >> >>
> > >> >> ---------------------------------------------------------------------
> > >> >> To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
> > >> >> For additional commands, e-mail: velocity-dev-help@jakarta.apache.org
> > >> >>
> > >> >>
> > >> >
> > >> >
> > >>
> > >>
> > >> ---------------------------------------------------------------------
> > >> To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
> > >> For additional commands, e-mail: velocity-dev-help@jakarta.apache.org
> > >>
> > >>
> > >
> > >
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: velocity-dev-help@jakarta.apache.org
> >
> >
>
>
> --
> Forio Business Simulations
>
> Will Glass-Husain
> wglass@forio.com
> www.forio.com
>
--
Forio Business Simulations
Will Glass-Husain
wglass@forio.com
www.forio.com
---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-dev-help@jakarta.apache.org
Re: I dream of a velocity expression custom JSP tag
Posted by Will Glass-Husain <wg...@forio.com>.
Hi Jeff,
Now I get it. If you built a simpler tag that always stored a String
object this would be easy-- just use Velocity.evaluate as I suggest.
But you want to evaluate an expression to a resulting object.
Seems to me that you want this to act similar to the Velocity #set.
You might start by looking at the class
o.a.v.runtime.parser.node.ASTSetDirective. The key line is:
Object value = right.value(context);
which evaluates the right hand side of the #set expression.
One way of approaching this is to consider that Velocity.evaluate()
basically ends up calling Node.render() which is a recursive series of
parser nodes that output to a Writer. You need a similar starting
point to call Node.value() which will recursively evaluate an
expression.
Just a few quick thoughts, hope they point you in a useful direction...
WILL
On 8/19/06, Jeff Schnitzer <je...@infohazard.org> wrote:
> I'm just evaluating Velocity expressions. The result of the expression
> should be an object, whereas Velocity.evaluate() renders output to a
> Writer as text. The method I'm looking for would look something like this:
>
> public Object evaluate(Context ctx, String expression);
>
> For example:
>
> ctx.put("now", Calendar.getInstance());
> TimeZone tz = (TimeZone)evaluate(ctx, "now.timeZone");
>
> The Introspector seems to be much, much lower level than this.
>
> Thanks,
> Jeff
>
> Will Glass-Husain wrote:
> > Not sure I get it. Are you making a new expression language or just
> > evaluating Velocity expressions?
> >
> > The introspector is what resolves objects and methods in Velocity.
> >
> > WILL
> >
> > On 8/19/06, Jeff Schnitzer <je...@infohazard.org> wrote:
> >> Velocity.evaluate() renders textual output to a Writer. For the
> >> expression language to work, I need to resolve objects. I can't find
> >> anything in the javadocs that might give me a hook.
> >>
> >> Any suggestions?
> >>
> >> I know, I need to wade through the code, but a few starting pointers
> >> would help.
> >>
> >> Thanks,
> >> Jeff
> >>
> >>
> >> Will Glass-Husain wrote:
> >> > Wow! As a both a Velocity enthusiast and JSTL junkie that sounds like
> >> > a really useful tag.
> >> >
> >> > It doesn't sound that hard to me. Extract the expression, call
> >> > Velocity.evaluate, and set the request attribute. I guess you'd have
> >> > to set up the context with all the beans first.
> >> >
> >> > WILL
> >> >
> >> >
> >> > On 8/17/06, Jeff Schnitzer <je...@infohazard.org> wrote:
> >> >> Short version: I wish for a JSP custom tag that will effectively
> >> let me
> >> >> use Velocity expressions instead of the anemic JSTL expressions.
> >> >>
> >> >> Long version:
> >> >>
> >> >> Velocity already has a custom JSP tag that lets me do this:
> >> >>
> >> >> <vel:velocity>
> >> >> #if(true) cool velocity stuff #end
> >> >> </vel:velocity>
> >> >>
> >> >> However, what I really really want is something that lets me use
> >> >> velocity expressions the way I would use JSTL expressions. The most
> >> >> important is this:
> >> >>
> >> >> <vel:set var="foo" value="${cool.velocity(syntax)}" />
> >> >>
> >> >> The inability of JSTL expressions to call arbitrary java methods
> >> results
> >> >> in muchhacking and hair pulling. Velocity expressions rock. I want
> >> >> them :-)
> >> >>
> >> >> How hard would it be to make a <vel:set> tag? I looked around the
> >> APIs
> >> >> but couldn't find anything helpful.
> >> >>
> >> >> Thanks,
> >> >> Jeff
> >> >>
> >> >> ---------------------------------------------------------------------
> >> >> To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
> >> >> For additional commands, e-mail: velocity-dev-help@jakarta.apache.org
> >> >>
> >> >>
> >> >
> >> >
> >>
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
> >> For additional commands, e-mail: velocity-dev-help@jakarta.apache.org
> >>
> >>
> >
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-dev-help@jakarta.apache.org
>
>
--
Forio Business Simulations
Will Glass-Husain
wglass@forio.com
www.forio.com
---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-dev-help@jakarta.apache.org
Re: I dream of a velocity expression custom JSP tag
Posted by Jeff Schnitzer <je...@infohazard.org>.
I'm just evaluating Velocity expressions. The result of the expression
should be an object, whereas Velocity.evaluate() renders output to a
Writer as text. The method I'm looking for would look something like this:
public Object evaluate(Context ctx, String expression);
For example:
ctx.put("now", Calendar.getInstance());
TimeZone tz = (TimeZone)evaluate(ctx, "now.timeZone");
The Introspector seems to be much, much lower level than this.
Thanks,
Jeff
Will Glass-Husain wrote:
> Not sure I get it. Are you making a new expression language or just
> evaluating Velocity expressions?
>
> The introspector is what resolves objects and methods in Velocity.
>
> WILL
>
> On 8/19/06, Jeff Schnitzer <je...@infohazard.org> wrote:
>> Velocity.evaluate() renders textual output to a Writer. For the
>> expression language to work, I need to resolve objects. I can't find
>> anything in the javadocs that might give me a hook.
>>
>> Any suggestions?
>>
>> I know, I need to wade through the code, but a few starting pointers
>> would help.
>>
>> Thanks,
>> Jeff
>>
>>
>> Will Glass-Husain wrote:
>> > Wow! As a both a Velocity enthusiast and JSTL junkie that sounds like
>> > a really useful tag.
>> >
>> > It doesn't sound that hard to me. Extract the expression, call
>> > Velocity.evaluate, and set the request attribute. I guess you'd have
>> > to set up the context with all the beans first.
>> >
>> > WILL
>> >
>> >
>> > On 8/17/06, Jeff Schnitzer <je...@infohazard.org> wrote:
>> >> Short version: I wish for a JSP custom tag that will effectively
>> let me
>> >> use Velocity expressions instead of the anemic JSTL expressions.
>> >>
>> >> Long version:
>> >>
>> >> Velocity already has a custom JSP tag that lets me do this:
>> >>
>> >> <vel:velocity>
>> >> #if(true) cool velocity stuff #end
>> >> </vel:velocity>
>> >>
>> >> However, what I really really want is something that lets me use
>> >> velocity expressions the way I would use JSTL expressions. The most
>> >> important is this:
>> >>
>> >> <vel:set var="foo" value="${cool.velocity(syntax)}" />
>> >>
>> >> The inability of JSTL expressions to call arbitrary java methods
>> results
>> >> in muchhacking and hair pulling. Velocity expressions rock. I want
>> >> them :-)
>> >>
>> >> How hard would it be to make a <vel:set> tag? I looked around the
>> APIs
>> >> but couldn't find anything helpful.
>> >>
>> >> Thanks,
>> >> Jeff
>> >>
>> >> ---------------------------------------------------------------------
>> >> To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
>> >> For additional commands, e-mail: velocity-dev-help@jakarta.apache.org
>> >>
>> >>
>> >
>> >
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
>> For additional commands, e-mail: velocity-dev-help@jakarta.apache.org
>>
>>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-dev-help@jakarta.apache.org
Re: I dream of a velocity expression custom JSP tag
Posted by Will Glass-Husain <wg...@forio.com>.
Not sure I get it. Are you making a new expression language or just
evaluating Velocity expressions?
The introspector is what resolves objects and methods in Velocity.
WILL
On 8/19/06, Jeff Schnitzer <je...@infohazard.org> wrote:
> Velocity.evaluate() renders textual output to a Writer. For the
> expression language to work, I need to resolve objects. I can't find
> anything in the javadocs that might give me a hook.
>
> Any suggestions?
>
> I know, I need to wade through the code, but a few starting pointers
> would help.
>
> Thanks,
> Jeff
>
>
> Will Glass-Husain wrote:
> > Wow! As a both a Velocity enthusiast and JSTL junkie that sounds like
> > a really useful tag.
> >
> > It doesn't sound that hard to me. Extract the expression, call
> > Velocity.evaluate, and set the request attribute. I guess you'd have
> > to set up the context with all the beans first.
> >
> > WILL
> >
> >
> > On 8/17/06, Jeff Schnitzer <je...@infohazard.org> wrote:
> >> Short version: I wish for a JSP custom tag that will effectively let me
> >> use Velocity expressions instead of the anemic JSTL expressions.
> >>
> >> Long version:
> >>
> >> Velocity already has a custom JSP tag that lets me do this:
> >>
> >> <vel:velocity>
> >> #if(true) cool velocity stuff #end
> >> </vel:velocity>
> >>
> >> However, what I really really want is something that lets me use
> >> velocity expressions the way I would use JSTL expressions. The most
> >> important is this:
> >>
> >> <vel:set var="foo" value="${cool.velocity(syntax)}" />
> >>
> >> The inability of JSTL expressions to call arbitrary java methods results
> >> in muchhacking and hair pulling. Velocity expressions rock. I want
> >> them :-)
> >>
> >> How hard would it be to make a <vel:set> tag? I looked around the APIs
> >> but couldn't find anything helpful.
> >>
> >> Thanks,
> >> Jeff
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
> >> For additional commands, e-mail: velocity-dev-help@jakarta.apache.org
> >>
> >>
> >
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-dev-help@jakarta.apache.org
>
>
--
Forio Business Simulations
Will Glass-Husain
wglass@forio.com
www.forio.com
---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-dev-help@jakarta.apache.org
Re: I dream of a velocity expression custom JSP tag
Posted by Jeff Schnitzer <je...@infohazard.org>.
Velocity.evaluate() renders textual output to a Writer. For the
expression language to work, I need to resolve objects. I can't find
anything in the javadocs that might give me a hook.
Any suggestions?
I know, I need to wade through the code, but a few starting pointers
would help.
Thanks,
Jeff
Will Glass-Husain wrote:
> Wow! As a both a Velocity enthusiast and JSTL junkie that sounds like
> a really useful tag.
>
> It doesn't sound that hard to me. Extract the expression, call
> Velocity.evaluate, and set the request attribute. I guess you'd have
> to set up the context with all the beans first.
>
> WILL
>
>
> On 8/17/06, Jeff Schnitzer <je...@infohazard.org> wrote:
>> Short version: I wish for a JSP custom tag that will effectively let me
>> use Velocity expressions instead of the anemic JSTL expressions.
>>
>> Long version:
>>
>> Velocity already has a custom JSP tag that lets me do this:
>>
>> <vel:velocity>
>> #if(true) cool velocity stuff #end
>> </vel:velocity>
>>
>> However, what I really really want is something that lets me use
>> velocity expressions the way I would use JSTL expressions. The most
>> important is this:
>>
>> <vel:set var="foo" value="${cool.velocity(syntax)}" />
>>
>> The inability of JSTL expressions to call arbitrary java methods results
>> in muchhacking and hair pulling. Velocity expressions rock. I want
>> them :-)
>>
>> How hard would it be to make a <vel:set> tag? I looked around the APIs
>> but couldn't find anything helpful.
>>
>> Thanks,
>> Jeff
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
>> For additional commands, e-mail: velocity-dev-help@jakarta.apache.org
>>
>>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-dev-help@jakarta.apache.org
Re: I dream of a velocity expression custom JSP tag
Posted by Will Glass-Husain <wg...@forio.com>.
Wow! As a both a Velocity enthusiast and JSTL junkie that sounds like
a really useful tag.
It doesn't sound that hard to me. Extract the expression, call
Velocity.evaluate, and set the request attribute. I guess you'd have
to set up the context with all the beans first.
WILL
On 8/17/06, Jeff Schnitzer <je...@infohazard.org> wrote:
> Short version: I wish for a JSP custom tag that will effectively let me
> use Velocity expressions instead of the anemic JSTL expressions.
>
> Long version:
>
> Velocity already has a custom JSP tag that lets me do this:
>
> <vel:velocity>
> #if(true) cool velocity stuff #end
> </vel:velocity>
>
> However, what I really really want is something that lets me use
> velocity expressions the way I would use JSTL expressions. The most
> important is this:
>
> <vel:set var="foo" value="${cool.velocity(syntax)}" />
>
> The inability of JSTL expressions to call arbitrary java methods results
> in muchhacking and hair pulling. Velocity expressions rock. I want
> them :-)
>
> How hard would it be to make a <vel:set> tag? I looked around the APIs
> but couldn't find anything helpful.
>
> Thanks,
> Jeff
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-dev-help@jakarta.apache.org
>
>
--
Forio Business Simulations
Will Glass-Husain
wglass@forio.com
www.forio.com
---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-dev-help@jakarta.apache.org