File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes Reload page without losing data Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Reload page without losing data" Watch "Reload page without losing data" New topic
Author

Reload page without losing data

Wilfred D'Souza
Greenhorn

Joined: Mar 09, 2004
Posts: 8
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


Best regards<br />Wilfred D'Souza
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
Moving to JSP since it is better then using JavaScript to solve the problem...
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61201
    
  66

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.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Jeroen Wenting
Ranch Hand

Joined: Oct 12, 2000
Posts: 5093
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).


42
Nicholas Cheung
Ranch Hand

Joined: Nov 07, 2003
Posts: 4982
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.


SCJP 1.2, OCP 9i DBA, SCWCD 1.3, SCJP 1.4 (SAI), SCJD 1.4, SCWCD 1.4 (Beta), ICED (IBM 287, IBM 484, IBM 486), SCMAD 1.0 (Beta), SCBCD 1.3, ICSD (IBM 288), ICDBA (IBM 700, IBM 701), SCDJWS, ICSD (IBM 348), OCP 10g DBA (Beta), SCJP 5.0 (Beta), SCJA 1.0 (Beta), MCP(70-270), SCBCD 5.0 (Beta), SCJP 6.0, SCEA for JEE5 (in progress)
Wilfred D'Souza
Greenhorn

Joined: Mar 09, 2004
Posts: 8
Thanx guyz,
I will try all of ur suggestions and let u know if I succeeded.
Thanx once again.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Reload page without losing data