• 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

Passing location info

 
Greenhorn
Posts: 29
Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

I am trying to write a Spring MVC based application, where an objects location is passed onto the JSP and further processing is done using javascript. I managed to get the list of objects in the dropdown, my requirement is: when the user selects one of the object from the drop down the latitude and longitude value for this object should be assigned to two variables in the javascript.

There is a separate class named Location which has the latitude and longitude. And object of Location is a member of the class being selected in the dropdown.

Please let me know how I can achieve this.

code:

 
Ranch Hand
Posts: 123
Firefox Browser Spring Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
3 solutions are below.

1. Use onchange attribute of the html select tag (whatever front-end framework you are using) and call the server (e.g. ajax, json, jquery) for the 2 items you need. For efficiency, call only when you need to, i.e. when you actually need those 2 data already.

since you are using spring mvc, adding a jquery/json service is simple. Look into Jackson and jquery.

2. If the list of locations is small, you can load the entire list (e.g. ajax, json, jquery, initial page load, etc.) and do search when needed. This is not scaleable. I do not advise on using this.

3. If you have no other alternatives, this is what I would use. Fast, efficient. No additional server call.

3. a. locString needs to be post-processed because it now contains not just location but also the 2 other fields
3. b. change
itemValue="location"
to
itemValue="locationLatitudeLongitudeDelimitedByBar"

3. c. as implied by #b. above, add a getLocationLatitudeLongitudeDelimitedByBar() method. Use a delimiter (e.g. bar "|") that doesn't occur in your data.

an example of data returned by getLocationLatitudeLongitudeDelimitedByBar() is below.
"NorthPole|010101|38362"

3. d. as you probably have guessed, you need to use onchange attribute of the html select tag or process it only when needed

-k

================================================================
[SpringSource Certified Spring Professional (Spring Certification) – Practice Tests]
 
Farmers know to never drive a tractor near a honey locust tree. But a tiny ad is okay:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic