• 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
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

iterating with a scriptlet, can't get the values into js arr

 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


I don't understand why I cant load the javascript array with the values of the java array in the scriptlet.

I'm open to any other ways to get the data into the javascript array ??? I'm sure this is something stupid.

You help is appreciated.
 
Marshal
Posts: 28290
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And what's the output of that scriptlet? If you're using a browser to look at the result, then use View Source to actually see the source.
 
Sheriff
Posts: 67750
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
... and when you do, chances are that you'll see that you are not generating valid JavaScript syntax.

(And really, scriptlets? In 2009?)
 
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

Bear Bibeault wrote:(And really, scriptlets? In 2009?)


Being retro is cool... now lemme alone; I have some disco to take care of.
 
Bear Bibeault
Sheriff
Posts: 67750
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

David Newton wrote:Being retro is cool... now lemme alone; I have some disco to take care of.


Some retro is cool. A classic car, for example. But some is not, platform boots for example.

Scriptlets are the platform boots of JSP.
 
chris gar
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bear Bibeault wrote:... and when you do, chances are that you'll see that you are not generating valid JavaScript syntax.

(And really, scriptlets? In 2009?)



I'm quite aware that I'm not generating valid javascript syntax, thus my post. As for the scriptlets, I'm simply trying to get to the root of my problem.

I'm calling an action with asynchronous javascript. Based on a user's selection in selectBox1 (onSelect()), the options for selectBox2 are supposed to be populated. I'm able to target the action just fine with the appropriate data(option selected in selectBox1), but I don't know how to get the results (a String array) back in my javascript (where I'm manipulating the DOM) to get the correct options in selectBox2.

Any suggestions?

 
Bear Bibeault
Sheriff
Posts: 67750
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There is no valid reason to be using scriptlets for new code in 2009.

You haven't really explained what you are doing very well. If you're just making an Ajax call to get the data to populate a select element, you can just return the data as a JSON construct and have the JavaScript use it to reconstruct the select element.

 
chris gar
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bear Bibeault wrote:There is no valid reason to be using scriptlets for new code in 2009.

You haven't really explained what you are doing very well. If you're just making an Ajax call to get the data to populate a select element, you can just return the data as a JSON construct and have the JavaScript use it to reconstruct the select element.



OK. I've abandoned the scriptlet route and tried to utilize json.

I'm still getting the results back from the action but I can't get the desired results to appear as the options in the select.





Here's the action


When a user selects a value from the dropdown att1, I want the dropdown op1 to display the results of the ajax call. The dropdown op1 contains operators for queries (=, !=, Like, etc.) Based on the type of attribute selected in the att1 dropdown, I want valid operators to appear (so for a float selection in att1, I don't want to display LIKE, etc). I will eventually do the same for the dropdown attval1 (which will require db lookup) but that should fall into place once I get op1 working.

I assume I need to do something else around "dojo.byId("op1").innerHTML = response ; " but I don't know what.
The results I get are
{"operators":[["= ","0"],["!= ","1"],["LIKE","3"],["~","4"]],"ops":"success"}

which certainly contains the data I need, but I don't know how to get [["= ","0"],["!= ","1"],["LIKE","3"],["~","4"]] of the result into the options of my select box. Certainly there is some call I can utilize rather than manually parsing.

Thanks again for your assistance.

 
Bear Bibeault
Sheriff
Posts: 67750
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You do not need to parse JSON yourself. At worst, you use the JavaScript eval() method. However, jQuery and Prototype have the means to automatically parse the returning JSON for you and I'd be surprised (and dismayed) if Dojo did not. I'd check out what values can be supplied for the handleAs option.

Once parsed, you just have a normal JavaScript data structure what you can use to adjust the contents of the select element. Example code for doing so is all over the net as this sort of "dependent dropdown" capability is sort of the poster child for Ajax.
 
Never trust an airline that limits their passengers to one carry on iguana. Put this tiny ad in your shoe:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic