Populating JavaScript Array from JSP List -


OK, maybe someone can help me with a problem that I'm trying to solve. Basically I have a JSP page which is available from a list of country items (from the method reference data to the spring portlet SimpleFormController, not completely relevant but just mentioning in the case). Each country has a set of province objects in the object and each province and country has a name field:

  the public category country {name of the private string; Private set & lt; Province & gt; Provinces; // gates and setters} public class province {name of the private string; // Gates and Searns}  

Now there are two drop down menus in countries and provinces in my JSP and I want to filter the provinces of the country. I am following it to select a chain in JavaScript.

Now I want a dynamic way of creating a JavaScript array from my content and before anybody mentions AJAX, it has gone out of the question because our project uses the portlet and we can use the DWR Like wanting to stay away from making a framework or servlet. Here I have done Javascript / JSP yet but it is not popping Array with anything:

  var country = new array (); & Lt; C: forEach item = "$ {countryList}" var = "country" varStatus = "status" & gt; Countries [status.index] = new array (); Country [status.index] ['country'] = $ {country.name}; Country [status.index] ['province'] = [[[& lt; C: forEach item = "$ {country.provinces}" var = "province" varStatus = "province state" & gt; '$ {Province.name}' & lt; C: If test = "$ {! Province status.last}" & gt; , & Lt; / C: if & gt; & Lt; / C: foreach & gt; ]; & Lt; / C: foreach & gt; Do anyone know that in the case given above, how to make Javascript Aariya in JSP or 'best practice' in this case? thank you in advanced!   

  var country = new array (); & Lt; C: forEach item = "$ {countryList}" var = "country" varStatus = "status" & gt; CountryDetails = New Object (); CountryDetails.country = $ {country.name}; Var provincial = new array (); & Lt; C: forEach item = "$ {country.provinces}" var = "province" varStatus = "province state" & gt; Provinces.push ($ {province.name}); & Lt; / C: foreach & gt; Country details. Source = province; Countries.push (countryDetails); & Lt; / C: foreach & gt;  

You now have something similar in JavaScript

  var country = [[country: "USA", province: ["Ohio", "other option : "New York", "California"]}, {Country: "Canada", Provincial: ["Ontario", "Northern Territory", "Saskatchewan"]},]  

Your Output I have to show the javascript like post.

  var country = [& lt; C: forEach items = "$ {countryList}" var = "country" varStatus = "status" & gt; {Country: '$ {country.name}', Province: [& lt; C: forEach item = "$ {country.provinces}" var = "province" varStatus = "province state" & gt; '$ {Province.name}' & lt; C: If test = "$ {! Province status.last}" & gt; , & Lt; / C: if & gt; & Lt; / C: foreach & gt; ]} & Lt; C: If test = "$ {! Status.last}" & gt; , & Lt; / C: if & gt; & Lt; / C: foreach & gt; ];  

Comments

Popular posts from this blog

windows - Heroku throws SQLITE3 Read only exception -

lex - Building a lexical Analyzer in Java -

python - rename keys in a dictionary -