• 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

Reload page without losing data

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I have a JSP which has a select box (which has data retrieved from a database). On the selected value of that box another select box (on the same page) should get updated from another database.
Could anyone help me on this one.
Thanx
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Moving to JSP since it is better then using JavaScript to solve the problem...
 
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
Two approaches come to mind:
1) The onselect handler of the select box resubmits the page whose server-side controller (preferable a servlet rather than JSP-embedded Java) interacts with the Model (or DB) to get the values for the second box. The page redraws itself with these values.
2) The onselect handler of the select box submits a request into a hidden iframe that does the DB dirty work and returns as its response a gaggle of Javascript that rewrites the options of the second select box.
Pick your poison.
 
Ranch Hand
Posts: 5093
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Another possible approach (which works best if the total dataset for all possible fills of the second box is not too large and fairly static) is to preload everything in a series of Javascript arrays and fill the second box using Javascript on the fly.
That's what I usually use as we want in our app to minimise backend calls (which have to run through a middleware layer over the network to software running on another machine which does the actual database access, in all a fairly expensive procedure).
 
Ranch Hand
Posts: 4982
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I agree with Jeroen.
If the information that preloaded into the JavaScript can be explored to public, it is a better option. You even can store the list into the session, so that every page that needs this does not require to query the DB via expensive backend calls.
Of course, if the information cannot be preloaded, the only way is to check with the backend server every time.
Nick.
 
Wilfred D'Souza
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanx guyz,
I will try all of ur suggestions and let u know if I succeeded.
Thanx once again.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic