aspose file tools*
The moose likes JSP and the fly likes display Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "display" Watch "display" New topic
Author

display

Hari priya
Ranch Hand

Joined: Mar 11, 2004
Posts: 134
Hi -

I have a jsp page that has a drop down list and a submit button and some text. When I hit submit, it fetches some info from the database and displays it on the current page.

My requirement - ithe new information should not get appended to the existing text on the page but should override it [only the text part] leaving the drop down list and the submit buton.

can some on please let me know how I can achieve this? I hope my question is clear. Thanks,
PS: Please let me know if there is any better way to do it.
[ August 16, 2004: Message edited by: Hari priya ]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61766
    
  67

You cannot refresh only part of a page. You can either put the portion of the page that is to be refreshed in an iframe, or repaint the whole page restoring the droplist to its previous state.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Hari priya
Ranch Hand

Joined: Mar 11, 2004
Posts: 134
thanks bear... I have been trying to use frameset but some how this doesn't seem to show up the frames... is what i am doing correct?

Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61766
    
  67

I would recommend against a frameset. When I do something similar, I use the single-page approach and simply make sure that the controls redisplay themselevs as appropriate. If you are going to used a framed approach, investigate a child iframe rather than an unweildly frameset.
Julian Kennedy
Ranch Hand

Joined: Aug 02, 2004
Posts: 823
Hari Priya,

Typically you would just refresh the whole page, droplist and button included. That's the simplest way of doing it.

If you prefer to use an <iframe>, you don't need a frameset for it. Look it up in an HTML reference if you've not used one before.

Jules

[Edit: Bear does not recommend using a framed approach -- see above]

[JK: I think I said "suggested", pertaining to the iframe reference in the earlier post Revisionist history now, eh? I wonder who'll be the first against the wall when the revolution comes?! ]

[Bear: true, but to me it sounded like you thought that was my primary suggestion... where it was more like a 'if you must use a framed approach...'. Violent agreement?]

[JK: Yes. We were saying exactly the same thing. Frames suck.]

[ August 16, 2004: Message edited by: Bear Bibeault ]

[ August 16, 2004: Message edited by: Julian Kennedy ]

[ August 16, 2004: Message edited by: Bear Bibeault ]
[ August 16, 2004: Message edited by: Julian Kennedy ]
Hari priya
Ranch Hand

Joined: Mar 11, 2004
Posts: 134
Hi Julian and Bear -

I feel refresing the entire page is a simpler option for me too as I already have a lot of javascript and jsp code in my page, so anything else is almost redesigning.

It might be a simple thing but I am a new to JSP and need help. Can you please tell me how to refresh the entire page with new data? I would prefer not to hit the refresh button.

I have used a form which contains the drop list and the submit button. when i click the submit btn, it should refer to the same page and also erase the old data (now how do i erase the old data if i am refreshing the same page? )

One option I can think of is re-directing to another jsp page and get the request object. But i would never know the name of the request attribute as the options in the drop list are generated dynamically.



Thanks for your time in attempting to solve my problem. may be i will ask more advanced questions after completing this project.
Hari

[ August 16, 2004: Message edited by: Hari priya ]
[ August 16, 2004: Message edited by: Hari priya ]
Sonny Gill
Ranch Hand

Joined: Feb 02, 2002
Posts: 1211

Originally posted by Hari priya:

I have used a form which contains the drop list and the submit button. when i click the submit btn, it should refer to the same page and also erase the old data (now how do i erase the old data if i am refreshing the same page?


Remember it is a JSP, and it is dynamic, so it does not have to be 'the same' every time it is refreshed. Submit a hidden parameter the second time the page is refreshed. And while generating the page, check for the presence of that hidden parameter, if it is there, show the new data, if it is not present, show the old data.
This way, when the user requests the page first time around, it will show the old data, and next time she refreshes, it will show the new data.
If it is not working, simplify your page, get it working, and then add the drop lists and everything else.

HTH
Sunny


The future is here. It's just not evenly distributed yet. - William Gibson
Consultant @ Xebia. Sonny Gill Tweets
Hari priya
Ranch Hand

Joined: Mar 11, 2004
Posts: 134
Thank you Sonny for giving me a solution. I am working towards it
[ August 17, 2004: Message edited by: Hari priya ]
Hari priya
Ranch Hand

Joined: Mar 11, 2004
Posts: 134
Hi again -

This is what I am trying to do. After selecting an option [uid] in the drop list, i am redirecting to the same page. However, I am unable to capture the value selected in the drop list [i was checking if uid was null]. Uid is always null in my case. What could be the problem? Thanks!

Sonny Gill
Ranch Hand

Joined: Feb 02, 2002
Posts: 1211

use request.getParameter("uid")
instead of getAttribute().
These two methods serve very different purposes, have a look at Javadocs or one of the tutorials available on the web(there's one on Sun's JSP site)
Jeroen Wenting
Ranch Hand

Joined: Oct 12, 2000
Posts: 5093
you can in fact refresh part of a page by using quite elaborate Javascript code which loads new content into a named html element (usually a div or span).

Can't show the code we use as it's proprietary, it's about a hundred lines of Javascript calling a servlet that forwards to a jsp that returns html with predetermined formatting to the javascript which then inserts it into an html control.


42
Hari priya
Ranch Hand

Joined: Mar 11, 2004
Posts: 134
Thank you for your replies. Yeah I figured out that I was calling the wrong request method .
himanshu patel
Ranch Hand

Joined: Feb 03, 2003
Posts: 205
I can think of one more way to do this using div as Jeroen suggested.

Ex. When the first time page is loaded , get all the texts from database corresponding to each text item in list. This will typically be in each different div block.

Now using javascipt make visible any default text and invisible all other text. Now when item is selected from the list, make corresponding
text visible and other invisible. This way i think we should be able to
refresh data without sending request to server. I have not tested it so
not so sure.

But this is advisable if we have few items in the list and has small corresponding data. Otherwise it would increase page load time.

I think Eric should be able to give some javascript tricks.


Originally posted by Jeroen Wenting:
you can in fact refresh part of a page by using quite elaborate Javascript code which loads new content into a named html element (usually a div or span).

Can't show the code we use as it's proprietary, it's about a hundred lines of Javascript calling a servlet that forwards to a jsp that returns html with predetermined formatting to the javascript which then inserts it into an html control.


If you want to become a rich, do not work for others but make others to work for you.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: display