You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Dmitri Colebatch <di...@nuix.com.au> on 2002/03/02 00:59:13 UTC

directives, alternative implementation

hey all,

firstly, this is my first usage of Velocity, so if there's an FAQ I should've read that answers this - please point (o;  (I have
read most of the stuff I've been able to find).  Secondly, I think this is probably more a dev question, but by rights, I should ask
here first, so I am (o:

ok... I'm trying to implement a javascript powered framework, allowing someone to write javascript servlet/action style classes, and
use them in their pages on the server side.  Velocity seems to be a good choice for the pages as javascript being a dynamicaly typed
interpreted language I need to be able to implement the glue between the pages and the javascript classes at runtime, which Velocity
looks like it'll let me do.

What I want to do, is in my servlet, put a couple of Javascript objects (implementing the Rhino Scriptable interface) int he
context.  Thing is, when I call

$myObject.foo()

in my template, I need that to call a method

jsFunction_foo()

on that object ... essentially every directive will need to change in some form for this to work.  So I'm looking in the
org.apache.velocity.runtime.parser.node package at classes like ASTReference, which appear to be responsible for handling all this.

So, onto my questions:

1. I've never used jjtree or Javacc before, and want to know how I should understand the way the node package is created (from what
I gather it(/parts of it) is(/are) generated by this.

2. Has anyone else done this sort of thing, for Rhino, or anyhting else, that I might be able to get a head start from?

3. The way I'm looking at things so far, is something like this.... for ASTIdentifier, I've added the following lines of code to
doIntrospection() after the last try...

        if( executor.isAlive() == false)
        {
            executor = new ScriptablePropertyExecutor( rsvc, data, identifier );
        }

and then made the new ScriptablePropertyExecutor a subclass of PropertyExecutor and overridden the discover method.  This seems to
be the right thing to do, but I think that I'm going to have to get all the pieces in the puzzle before it'll work properly.

ok - so if anyone can offer any feedback, that would be great...  if not, I might try the dev list.

cheers, and tia
dim




--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: directives, alternative implementation

Posted by Corneil du Plessis <co...@mweb.co.za>.
I have had some success doing a JavaScriptToolbox. The only problem is send
more than text parameters into the script.

It would look like this:
$context.toolbox.js.eval("scriptfile.js", "myfunction('$var')")

myfunction inside scriptfile.js will be called and the result will be
available in velocity. This ideal where some complex calculations or
translations needs to be done.

Corneil du Plessis
(h) +27 (11) 918-1592
(w) +27 (82) 802-5768

-----Original Message-----
From: Dmitri Colebatch [mailto:dim@bigpond.net.au]
Sent: Saturday, March 02, 2002 4:44 AM
To: Velocity Users List
Subject: Re: directives, alternative implementation


Hi Geir,

Firstly - thanks for the quick response...  took 4 hours for the mail to
leave my desktop and get to the list, and then all of a
couple of minutes for you to respond (o:

> > ok... I'm trying to implement a javascript powered framework, allowing
someone
> > to write javascript servlet/action style classes, and
> > use them in their pages on the server side.  Velocity seems to be a good
> > choice for the pages as javascript being a dynamicaly typed
> > interpreted language I need to be able to implement the glue between the
pages
> > and the javascript classes at runtime, which Velocity
> > looks like it'll let me do.
>
> Why do you want to do this?

lol... I knew someone would ask this... its mainly just out of interest...
and also I have a friend who knows javascript very well,
but only works client side... him and I want to be able to make hobby sites,
and I see this as a way for him to develop logic when
he needs without having to learn java....

> > What I want to do, is in my servlet, put a couple of Javascript objects
> > (implementing the Rhino Scriptable interface) int he
> > context.  Thing is, when I call
> >
> > $myObject.foo()
> >
> > in my template, I need that to call a method
> >
> > jsFunction_foo()
> >
> > on that object ... essentially every directive will need to change in
some
> > form for this to work.  So I'm looking in the
> > org.apache.velocity.runtime.parser.node package at classes like
ASTReference,
> > which appear to be responsible for handling all this.
>
> Why do the directives have to change?  Why not wrap the javascript stuff
in
> a Java class?

because the java class needs to be compiled and DynamicProxies dont work
with reflection, and the javascript is not available at
compile time.  Other options I see are:
 - generating java source from the javascript using some customer generator
and compiling that at runtime... yuk
 - using BCEL to generate bytecode with the appropriate interface.... this
might be a better option, but I've never used BCEL, so
I'm not sure...

> > 1. I've never used jjtree or Javacc before, and want to know how I
should
> > understand the way the node package is created (from what
> > I gather it(/parts of it) is(/are) generated by this.
>
> That really isn't a question.

correct... I'll re-phrase... is there anything I should know when changing
the contents of the node package?  The readme hints there
is, but I'm missing the full view so am not sure.

> > 3. The way I'm looking at things so far, is something like this.... for
> > ASTIdentifier, I've added the following lines of code to
> > doIntrospection() after the last try...
> >
> >       if( executor.isAlive() == false)
> >       {
> >           executor = new ScriptablePropertyExecutor( rsvc, data,
identifier );
> >       }
> >
> > and then made the new ScriptablePropertyExecutor a subclass of
> > PropertyExecutor and overridden the discover method.  This seems to
> > be the right thing to do, but I think that I'm going to have to get all
the
> > pieces in the puzzle before it'll work properly.
> >
> > ok - so if anyone can offer any feedback, that would be great...  if
not, I
> > might try the dev list.
>
> My question - why do this by changing velocity?  Why not put a layer in
> between the javascript and Velocity via a normal Java class?

see above explanation.  I hope that's clear.

thanks again for the quick response... hopefully the picture is a little
clearer now.... I'll look forward to more feedback.

thanks
dim




--
To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
For additional commands, e-mail:
<ma...@jakarta.apache.org>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: directives, alternative implementation

Posted by Dmitri Colebatch <di...@bigpond.net.au>.
Hi Geir,

Firstly - thanks for the quick response...  took 4 hours for the mail to leave my desktop and get to the list, and then all of a
couple of minutes for you to respond (o:

> > ok... I'm trying to implement a javascript powered framework, allowing someone
> > to write javascript servlet/action style classes, and
> > use them in their pages on the server side.  Velocity seems to be a good
> > choice for the pages as javascript being a dynamicaly typed
> > interpreted language I need to be able to implement the glue between the pages
> > and the javascript classes at runtime, which Velocity
> > looks like it'll let me do.
>
> Why do you want to do this?

lol... I knew someone would ask this... its mainly just out of interest... and also I have a friend who knows javascript very well,
but only works client side... him and I want to be able to make hobby sites, and I see this as a way for him to develop logic when
he needs without having to learn java....

> > What I want to do, is in my servlet, put a couple of Javascript objects
> > (implementing the Rhino Scriptable interface) int he
> > context.  Thing is, when I call
> >
> > $myObject.foo()
> >
> > in my template, I need that to call a method
> >
> > jsFunction_foo()
> >
> > on that object ... essentially every directive will need to change in some
> > form for this to work.  So I'm looking in the
> > org.apache.velocity.runtime.parser.node package at classes like ASTReference,
> > which appear to be responsible for handling all this.
>
> Why do the directives have to change?  Why not wrap the javascript stuff in
> a Java class?

because the java class needs to be compiled and DynamicProxies dont work with reflection, and the javascript is not available at
compile time.  Other options I see are:
 - generating java source from the javascript using some customer generator and compiling that at runtime... yuk
 - using BCEL to generate bytecode with the appropriate interface.... this might be a better option, but I've never used BCEL, so
I'm not sure...

> > 1. I've never used jjtree or Javacc before, and want to know how I should
> > understand the way the node package is created (from what
> > I gather it(/parts of it) is(/are) generated by this.
>
> That really isn't a question.

correct... I'll re-phrase... is there anything I should know when changing the contents of the node package?  The readme hints there
is, but I'm missing the full view so am not sure.

> > 3. The way I'm looking at things so far, is something like this.... for
> > ASTIdentifier, I've added the following lines of code to
> > doIntrospection() after the last try...
> >
> >       if( executor.isAlive() == false)
> >       {
> >           executor = new ScriptablePropertyExecutor( rsvc, data, identifier );
> >       }
> >
> > and then made the new ScriptablePropertyExecutor a subclass of
> > PropertyExecutor and overridden the discover method.  This seems to
> > be the right thing to do, but I think that I'm going to have to get all the
> > pieces in the puzzle before it'll work properly.
> >
> > ok - so if anyone can offer any feedback, that would be great...  if not, I
> > might try the dev list.
>
> My question - why do this by changing velocity?  Why not put a layer in
> between the javascript and Velocity via a normal Java class?

see above explanation.  I hope that's clear.

thanks again for the quick response... hopefully the picture is a little clearer now.... I'll look forward to more feedback.

thanks
dim




--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: directives, alternative implementation

Posted by "Geir Magnusson Jr." <ge...@optonline.net>.
On 3/1/02 6:59 PM, "Dmitri Colebatch" <di...@nuix.com.au> wrote:

> hey all,
> 
> firstly, this is my first usage of Velocity, so if there's an FAQ I should've
> read that answers this - please point (o;  (I have
> read most of the stuff I've been able to find).  Secondly, I think this is
> probably more a dev question, but by rights, I should ask
> here first, so I am (o:
> 
> ok... I'm trying to implement a javascript powered framework, allowing someone
> to write javascript servlet/action style classes, and
> use them in their pages on the server side.  Velocity seems to be a good
> choice for the pages as javascript being a dynamicaly typed
> interpreted language I need to be able to implement the glue between the pages
> and the javascript classes at runtime, which Velocity
> looks like it'll let me do.
> 

Why do you want to do this?

> What I want to do, is in my servlet, put a couple of Javascript objects
> (implementing the Rhino Scriptable interface) int he
> context.  Thing is, when I call
> 
> $myObject.foo()
> 
> in my template, I need that to call a method
> 
> jsFunction_foo()
> 
> on that object ... essentially every directive will need to change in some
> form for this to work.  So I'm looking in the
> org.apache.velocity.runtime.parser.node package at classes like ASTReference,
> which appear to be responsible for handling all this.

Why do the directives have to change?  Why not wrap the javascript stuff in
a Java class?

> 
> So, onto my questions:
> 
> 1. I've never used jjtree or Javacc before, and want to know how I should
> understand the way the node package is created (from what
> I gather it(/parts of it) is(/are) generated by this.

That really isn't a question.
 
> 2. Has anyone else done this sort of thing, for Rhino, or anyhting else, that
> I might be able to get a head start from?
> 
> 3. The way I'm looking at things so far, is something like this.... for
> ASTIdentifier, I've added the following lines of code to
> doIntrospection() after the last try...
> 
>       if( executor.isAlive() == false)
>       {
>           executor = new ScriptablePropertyExecutor( rsvc, data, identifier );
>       }
> 
> and then made the new ScriptablePropertyExecutor a subclass of
> PropertyExecutor and overridden the discover method.  This seems to
> be the right thing to do, but I think that I'm going to have to get all the
> pieces in the puzzle before it'll work properly.
> 
> ok - so if anyone can offer any feedback, that would be great...  if not, I
> might try the dev list.

My question - why do this by changing velocity?  Why not put a layer in
between the javascript and Velocity via a normal Java class?

-- 
Geir Magnusson Jr.                                     geirm@optonline.net
System and Software Consulting
POC lives!


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>