velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "jonah benton" <jo...@jonah.com>
Subject Re: can method params be javascript?
Date Wed, 03 Jul 2002 04:28:27 GMT
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" <gary@grobe.net>
To: "Velocity Users List" <velocity-user@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:
<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