You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by "G.L. Grobe" <ga...@grobe.net> on 2002/07/03 04:22:45 UTC

can method params be javascript?

Anyone happen to know if it's possible to pass a javascript property through a velocity method (and if so, what the syntax is like) ? Something like ...

#foreach ( $key in $productList.keySet( my_javascript_property_somehow_here ) )
 ...
#end

And here's the javascript property (which returns a string) that I want to pass into the velocity method above ... (of course I can shorten this to a js function, etc...)

document.myForm.myName[document.myForm.myName.selectedIndex].value

Re: can method params be javascript?

Posted by jonah benton <jo...@jonah.com>.
Hi Gary,

The simplest, though not the most elegant, way to do this is to code pageA
to take an optional request parameter for each <select> box. If no request
parameters are passed to the page, then query the database for the values
for the first <select> box. If the request parameter for <select> box 1 has
a value, then display the value in place of <select> box 1 and query the
database for the values for <select> box 2, based on the value from <select>
box 1.

Then in each <select> box onChange() handler, you'll need to do something
like:

location.href="pageA?select1Param=${value1}&select2Param=${value2}..."

In other words, the onChange() event initiates a request to the server for
the entire page, with parameters indicating the selections that have already
been made. Then server side code populates one or more of the <select> boxes
according to the selections already made.

In other other words, the only way to use a property from javascript as the
parameter to a method in velocity is to send it to the server in the form of
a new request for the entire page, with the property as a request parameter.

HTH,

Jonah

----- Original Message -----
From: "G.L. Grobe" <ga...@grobe.net>
To: "Velocity Users List" <ve...@jakarta.apache.org>
Sent: Tuesday, July 02, 2002 11:11 PM
Subject: Re: can method params be javascript?


> I didn't understand the point on moving the logic to the server side.
Though
> I can see how what I had tried to do would not work because the parsing is
> on the server side. To clarify the problem, here's what it is I'm trying
to
> do ...
>
> When the user goes to pageA, a <select ...> element using a velocity
method
> populates the <option ...> values. Then using an onChange() from that
> <select ...> element, I'm trying to pass the <option ...> value that was
> selected and pass it into another velocity method that will filter a dbase
> query so as to populate the second <select ...> element's list box. Then
do
> the same w/ a third <select ...> from the selection of the second.
>
> Any help much appreciated.
>
> > > Anyone happen to know if it's possible to pass a javascript property
> > > through a velocity method (and if so, what the syntax is like) ?
> > > Something like ...
> > >
> > > #foreach ( $key in $productList.keySet(
> > > my_javascript_property_somehow_here ) )
> > >  ...
> > > #end
> >
> > No. VM parsing is performed on the server side, whereas JavaScript
> > parsing is performed on the client side. They're two seperate systems.
> > You can, however, do this:
> >
> > form1.vm:
> > <form action="form2.vm" name=form1>
> >   <input type=hidden name=jscriptVar>
> >   <input type=button onClick="document.form1.jscriptVar = 'foo';
> > document.form1.submit()">
> > </form>
> >
> > form2.vm:
> > <p>jscriptVar is now: $jscriptVar
> >
> > > And here's the javascript property (which returns a string) that I
want
> > > to pass into the velocity method above ... (of course I can shorten
this
> > > to a js function, etc...)
> > >
> > > document.myForm.myName[document.myForm.myName.selectedIndex].value
> >
> > Nope. Pass the value as a request attribute instead. If the value is set
> >   by some javascript on the page, either move the logic into the
> > server-side Java or have a mechanism which will pass the javascript
> > value through to the server and redraw the page.
>
>
>
>
> --
> 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: can method params be javascript?

Posted by "Geir Magnusson Jr." <ge...@adeptra.com>.
On 7/2/02 11:34 PM, "G.L. Grobe" <ga...@grobe.net> wrote:

> Gier, heh, thanks ... I understood that part. But it was Mike's solution to
> moving the logic to the server side that I didn't understand, or at least in
> the scenario I'm trying to use it in. To try to be clearer, it was the
> solution itself I didn't get.
> 

Oh, jeeze.  Sorry.  I'm too tired :)  [and really embarrassed...]

I'll go to bed now...


-- 
Geir Magnusson Jr. 
Research & Development, Adeptra Inc.
geirm@adeptra.com
+1-203-247-1713



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


Re: can method params be javascript?

Posted by "G.L. Grobe" <ga...@grobe.net>.
Gier, heh, thanks ... I understood that part. But it was Mike's solution to
moving the logic to the server side that I didn't understand, or at least in
the scenario I'm trying to use it in. To try to be clearer, it was the
solution itself I didn't get.

> > I didn't understand the point on moving the logic to the server side.
Though
> > I can see how what I had tried to do would not work because the parsing
is
> > on the server side. To clarify the problem, here's what it is I'm trying
to
> > do ...
> >
> > When the user goes to pageA, a <select ...> element using a velocity
method
> > populates the <option ...> values. Then using an onChange() from that
> > <select ...> element, I'm trying to pass the <option ...> value that was
> > selected and pass it into another velocity method that will filter a
dbase
> > query so as to populate the second <select ...> element's list box. Then
do
> > the same w/ a third <select ...> from the selection of the second.
> >
> > Any help much appreciated.
>
> The Velocity code gets executed on the server, when the page is rendered
and
> sent to the client.
>
> The Javascript, such as onChange(), is executed after the page has arrived
> at the client, so at this point, all the Velocity processing is done.
>
> Does this clear it up?



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


Re: can method params be javascript?

Posted by "Geir Magnusson Jr." <ge...@adeptra.com>.
On 7/2/02 11:11 PM, "G.L. Grobe" <ga...@grobe.net> wrote:

> I didn't understand the point on moving the logic to the server side. Though
> I can see how what I had tried to do would not work because the parsing is
> on the server side. To clarify the problem, here's what it is I'm trying to
> do ...
> 
> When the user goes to pageA, a <select ...> element using a velocity method
> populates the <option ...> values. Then using an onChange() from that
> <select ...> element, I'm trying to pass the <option ...> value that was
> selected and pass it into another velocity method that will filter a dbase
> query so as to populate the second <select ...> element's list box. Then do
> the same w/ a third <select ...> from the selection of the second.
> 
> Any help much appreciated.

The Velocity code gets executed on the server, when the page is rendered and
sent to the client.

The Javascript, such as onChange(), is executed after the page has arrived
at the client, so at this point, all the Velocity processing is done.

Does this clear it up?

-- 
Geir Magnusson Jr. 
Research & Development, Adeptra Inc.
geirm@adeptra.com
+1-203-247-1713



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


Re: can method params be javascript?

Posted by "G.L. Grobe" <ga...@grobe.net>.
I didn't understand the point on moving the logic to the server side. Though
I can see how what I had tried to do would not work because the parsing is
on the server side. To clarify the problem, here's what it is I'm trying to
do ...

When the user goes to pageA, a <select ...> element using a velocity method
populates the <option ...> values. Then using an onChange() from that
<select ...> element, I'm trying to pass the <option ...> value that was
selected and pass it into another velocity method that will filter a dbase
query so as to populate the second <select ...> element's list box. Then do
the same w/ a third <select ...> from the selection of the second.

Any help much appreciated.

> > Anyone happen to know if it's possible to pass a javascript property
> > through a velocity method (and if so, what the syntax is like) ?
> > Something like ...
> >
> > #foreach ( $key in $productList.keySet(
> > my_javascript_property_somehow_here ) )
> >  ...
> > #end
>
> No. VM parsing is performed on the server side, whereas JavaScript
> parsing is performed on the client side. They're two seperate systems.
> You can, however, do this:
>
> form1.vm:
> <form action="form2.vm" name=form1>
>   <input type=hidden name=jscriptVar>
>   <input type=button onClick="document.form1.jscriptVar = 'foo';
> document.form1.submit()">
> </form>
>
> form2.vm:
> <p>jscriptVar is now: $jscriptVar
>
> > And here's the javascript property (which returns a string) that I want
> > to pass into the velocity method above ... (of course I can shorten this
> > to a js function, etc...)
> >
> > document.myForm.myName[document.myForm.myName.selectedIndex].value
>
> Nope. Pass the value as a request attribute instead. If the value is set
>   by some javascript on the page, either move the logic into the
> server-side Java or have a mechanism which will pass the javascript
> value through to the server and redraw the page.




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


Re: can method params be javascript?

Posted by Michael Pearson <pe...@intecgroup.com.au>.
G.L. Grobe wrote:
> Anyone happen to know if it's possible to pass a javascript property
> through a velocity method (and if so, what the syntax is like) ?
> Something like ...
> 
> #foreach ( $key in $productList.keySet(
> my_javascript_property_somehow_here ) )
>  ...
> #end

No. VM parsing is performed on the server side, whereas JavaScript 
parsing is performed on the client side. They're two seperate systems. 
You can, however, do this:

form1.vm:
<form action="form2.vm" name=form1>
  <input type=hidden name=jscriptVar>
  <input type=button onClick="document.form1.jscriptVar = 'foo'; 
document.form1.submit()">
</form>

form2.vm:
<p>jscriptVar is now: $jscriptVar

> And here's the javascript property (which returns a string) that I want
> to pass into the velocity method above ... (of course I can shorten this
> to a js function, etc...)
> 
> document.myForm.myName[document.myForm.myName.selectedIndex].value

Nope. Pass the value as a request attribute instead. If the value is set 
  by some javascript on the page, either move the logic into the 
server-side Java or have a mechanism which will pass the javascript 
value through to the server and redraw the page.

-- 
Michael Pearson
Intec Consulting Group
Tel: +61 8 8359 2332
pearson@intecgroup.com.au


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