velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Corneil du Plessis" <corneil....@mweb.co.za>
Subject RE: directives, alternative implementation
Date Sat, 02 Mar 2002 10:39:56 GMT
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:
<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>


Mime
View raw message