• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Total newby javascript question

 
Ranch Hand
Posts: 681
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have no experience of java script, trying to do the following create two selects, the second select is dependent on the first. I can do thsi in java no problem, but have been told to use JavaScript also has its a very old app it does not have AJAX so its javascript all the way.

Looking on the net I found a JQuery pluging jquery.doubleSelect.js.

Which does what I need it to do, what I need to do is set the values.



These are values hard coded, what I have is a ArrayList of objects each object contains a ararylist of objects which will go in the second select.

I have no idea how to convert acolloction of java objects into a collection of javacript objects to loop through.

I have googled but just got java vs javascripts what the difference none that really show you how to use java an javascrip together.

Thanks for any help
 
Ranch Hand
Posts: 249
Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I assume this is on a jsp page, so I would do something like this :



Hopefully that is what you're looking for
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Except that you'd use JSTL, because scriptlets are horrible.
 
Tony Evans
Ranch Hand
Posts: 681
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
so if I had a object say


City being another object, so for every country selected the second pull down will contain all the citys for that country.
so the javascript code


would translate to


or JSTL



with the countryArray passed into the request object

Can a javascriptArray be a array of objects that can contain an array of java objects.

Or do I need to declare such an object an build it up parameter by paramter.

Is there a real good java script java link I could look at.

Thanks for your Help
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

No, you still need to build up the JavaScript by looping over the Java array.

You're over-complicating this: remember, JSP just creates HTML, which in turn contains the JavaScript. How would you do this if you were building an HTML table out of each entry? (With the caveat that you *must* use JavaScript-safe values--what if a country had a quote in it?)

Another option, perhaps much cleaner, is to convert the country array to JSON on the server side (there are libraries to do this) and just use that.
 
Tony Evans
Ranch Hand
Posts: 681
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the reply is thuis legal it doesnt work yet but is it on at least one of the right tracks for solving the problem.


Takes the country list out of the request for each one sets country name country id and for the second select sets each city an city id from that country city list
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sort of, but man, that's ugly. That's why I suggested building the JSON on the server side, for which there are several library alternatives.
 
Tony Evans
Ranch Hand
Posts: 681
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Got it working

Yes I know its ugly but it means that I dont have to go back to the server all the data is in the request object. That way the page does not need to be refreshed.
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You've misunderstood.

You're already sending the data from the server. Send it as JSON rather than building JSON on the client side.
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Tony Evans wrote:JavaScript also has its a very old app it does not have AJAX so its javascript all the way.



FYI: Ajax is JavaScript and it does not matter if the application is old or new.

Eric
 
I can't renounce my name. It's on all my stationery! And hinted in this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic