struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Struts Newsgroup (@Basebeans.com) <str...@basebeans.com>
Subject Re: Passing JavaScript variable to a Java Scriptlet on a JSP page
Date Sat, 20 Apr 2002 03:25:01 GMT
Subject: Re: Passing JavaScript variable to a Java Scriptlet on a JSP page
From: Matt Raible <matt@raibledesigns.com>
 ===
#2 can be done much easier using one of the Javascript Remote Scripting
libraries out there.

www.ashleyit.com has a good one.



On 4/17/02 8:36 PM, in article
mailman.1019097420.16279.struts@basebeans.com, "John Jones"
<john@kingchompy.com> wrote:

> You're trying to merge client side code and server side code. Your server
> side code has no idea what the country variable is. Here are only two ways
> to do this:
> 
> 1. Build javascript arrays of the information dynamically on the server side
> and build the proper associations between the data using javascript. Then
> build the function to act on that data on the onChange events on the select
> boxes.
> 
> or
> 
> 2. Create 1 pixel frame on right side of screen and when you select an
> option in your select box, have a javascript function refresh that frame and
> have some JavaScript arrays print out over there and using the onLoad
> command for that frame, populate the select box on your main page based on
> the value selected. This option is kind of klugy, but could be fun. :-) This
> is really probably only good for intranet type application where everyone
> has guaranteed fast connection over a LAN.
> 
> ----- Original Message -----
> From: "sanjeev_dutt" <sanjeev_dutt@infy.com>
> To: "Struts Users Mailing List" <struts-user@jakarta.apache.org>
> Sent: Monday, April 15, 2002 9:04 AM
> Subject: RE: Passing JavaScript variable to a Java Scriptlet on a JSP page
> 
> 
> Hi Oliver,
> 
> The main issue here is that I don't want to reload the page.
> Is there some way this could be done without reloading the page ?
> 
> Thanks
> Sanjeev
> 
> -----Original Message-----
> From: Oliver Reflé [mailto:o.refle@gmx.de]
> Sent: Monday, April 15, 2002 6:26 PM
> To: Struts Users Mailing List
> Subject: RE: Passing JavaScript variable to a Java Scriptlet on a JSP
> page
> 
> 
> Why don't you try it like this,
> your Option list could be derived from a collection which is stored as an
> attribute of the page.
> Each time you select a value you can call a javascript funtion which filters
> this collection.
> 
> Maybe your data is stored like that
> germany.bavaria.nuremberg
> englang.blabla.london
> 
> so you can filter the data, then reload the the page(don't forget to
> set again your collection as attribute)
> 
> -----Original Message-----
> From: sanjeev_dutt [mailto:sanjeev_dutt@infy.com]
> Sent: Monday, April 15, 2002 2:49 PM
> To: Struts Users Mailing List
> Subject: RE: Passing JavaScript variable to a Java Scriptlet on a JSP
> page
> 
> 
> Hi Oliver,
> 
> I am forced to do that. Actually on my JSP I have three lookups: Country,
> State and City.
> If the user choses a particular country, then he should be able to see only
> the corresponding states in the states lookup.
> This is where the JavaScript comes in.
> 
> Any other suggestions to implement this ?
> 
> Thanks
> Sanjeev
> 
> 
> 
> -----Original Message-----
> From: Oliver Reflé [mailto:o.refle@gmx.de]
> Sent: Monday, April 15, 2002 6:10 PM
> To: Struts Users Mailing List
> Subject: RE: Passing JavaScript variable to a Java Scriptlet on a JSP
> page
> 
> 
> I don't know exactly why you want to do that ?
> Why don't you use
> <% Hashtable states = new Hashtable();
> states = Combo.getStates(country);
> ....
> %>
> and then you use
> Country: <%=country.toString()%>
> 
> You don't need to use this javascript stuff, cause the disadvantage
> is that you execute this document.write stuff on the client side.
> You first execute you java scriptlet, the transfer the date to the
> client and there the javascript code is executed.
> 
> So it would be easier if you would only work with Java scriptlets or Tags
> here
> 
> Oliver
> 
> -----Original Message-----
> From: sanjeev_dutt [mailto:sanjeev_dutt@infy.com]
> Sent: Monday, April 15, 2002 2:32 PM
> To: Struts Users Mailing List
> Subject: Passing JavaScript variable to a Java Scriptlet on a JSP page
> 
> 
> Hi,
> 
> I have this piece of code on my JSP:
> 
> <Script language = "javascript">
> function fnGetStates()
> {
> country = document.searchAcctForm.cboAcctAddrCountry.value;
> alert(country);
> document.write('<% Hashtable states = new Hashtable(); %>');
> document.write('<% states = Combo.getStates(country);%>');
> document.write('<% Enumeration state = states.keys(); %>');
> document.write('<% while (state.hasMoreElements()) { %>');
> document.write('<% String statecode = (String)state.nextElement(); %>');
> document.write('<% String sts = (String)states.get(statecode); %>');
> document.write('<html:option value="<%= statecode %>"><%= sts
> %></html:option>');
> document.write('<%  } %>');
> }
> </Script>
> 
> 
> The problem is that "alert" is able to show the value of country. But within
> the document.write, It  is not able to get the value of "country". It throws
> the following error :
> 
> ~:\citione\web\WEB-INF\_tmp_war_myserver_myserver_web\jsp_servlet\_jsp\_sear
> ch\__searchacct.java:801: cannot resolve symbol
> probably occurred due to an error in /jsp/search/searchacct.jsp line 197:
> document.write('<% states = Combo.getStates(country);%>');
> Could some one help ?
> Thanks
> Sanjeev
> 
> 
> --
> To unsubscribe, e-mail:
> <mailto:struts-user-unsubscribe@jakarta.apache.org>
> For additional commands, e-mail:
> <mailto:struts-user-help@jakarta.apache.org>
> 
> 
> --
> To unsubscribe, e-mail:
> <mailto:struts-user-unsubscribe@jakarta.apache.org>
> For additional commands, e-mail:
> <mailto:struts-user-help@jakarta.apache.org>
> 
> 
> --
> To unsubscribe, e-mail:
> <mailto:struts-user-unsubscribe@jakarta.apache.org>
> For additional commands, e-mail:
> <mailto:struts-user-help@jakarta.apache.org>
> 
> 
> --
> To unsubscribe, e-mail:
> <mailto:struts-user-unsubscribe@jakarta.apache.org>
> For additional commands, e-mail:
> <mailto:struts-user-help@jakarta.apache.org>
> 
> 
> --
> To unsubscribe, e-mail:
> <mailto:struts-user-unsubscribe@jakarta.apache.org>
> For additional commands, e-mail:
> <mailto:struts-user-help@jakarta.apache.org>
> 
> 
> 
> --
> To unsubscribe, e-mail:   <mailto:struts-user-unsubscribe@jakarta.apache.org>
> For additional commands, e-mail: <mailto:struts-user-help@jakarta.apache.org>
> 


--
To unsubscribe, e-mail:   <mailto:struts-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:struts-user-help@jakarta.apache.org>


Mime
View raw message