• 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

iterating hashmap in jsp using value of dropdown as key

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a a hashmap in request attribute which is available to jsp file where i have a dropdown. Hashmap kay= value of this dropdown.
As and when I select CLT i want to perform some opertation depending on value associated with that key in hashmap.

How can I achieve this
 
Bartender
Posts: 1810
28
jQuery Netbeans IDE Eclipse IDE Firefox Browser MySQL Database Chrome Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Your question isn't real clear to me (what is CLT?) but that sort of user interface interaction sounds like a job for JavaScript.
 
shriya hegde
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Apologies for not being clear. I mean to say when I select any value from dropdown , that value should be passed as key to hashmap and get the value.

What I am trying for this is
on selection of dropdown value, i am calling javascript function and pass selected value of dropdown as parameter. Inside javascript function I have written scriptlet to do hashmap.get();
But I am not able to send that dropdown value as parameter to hashmap.get method. There is no form submit between dropdown selection and calling this function

Any suggestions?
 
J. Kevin Robbins
Bartender
Posts: 1810
28
jQuery Netbeans IDE Eclipse IDE Firefox Browser MySQL Database Chrome Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry I'm still trying to sort this out. Why not just build your dropdown based on the keys and values in the map? Then use the change event in JavaScript to get the selected value.
 
J. Kevin Robbins
Bartender
Posts: 1810
28
jQuery Netbeans IDE Eclipse IDE Firefox Browser MySQL Database Chrome Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So let's say your servlet looks like this:

Your jsp will look like this:


That will give you a dropdown (it's a select/option element to be precise) that has the keys and values of your map. From here you should be able to use JavaScript to detect a change in the select/option control and get the selected value. I recommend JQuery, look at the .change event.
 
Sheriff
Posts: 67746
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

shriya hegde wrote:Inside javascript function I have written scriptlet to do hashmap.get();



1) Scriptlets? In 2014?

2) Scriptlets run on the server, so putting them inside a JavaScript function to execute on the client makes no sense. Please read this article to understand how JSP works.
 
Ranch Hand
Posts: 355
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


What I am trying for this is
on selection of dropdown value, i am calling javascript function and pass selected value of dropdown as parameter. Inside javascript function I have written scriptlet to do hashmap.get();


Remember a jsp page is translated to a servlet before producing an html page that is displayed at the client side. So your java code(which is executed first) that you have put in the javascript function will no longer be there after the html page is rendered. If in your dropdown list the actual value of any option element is equal to its corresponding displayed value, i see no need of doing further work. But if these two values are not the same, eg:<option value="key">value</option> where key is different from value, then you can append the value to the key using a separator so that in your javascript function you can easily break the actual value of your select element value and retrieve the displayed value. Eg: using "_" as seperator, you will have ..<option value="key_value">value</option>
Hope that will help.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic