This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes JSP and the fly likes Submit to Same Page Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Submit to Same Page" Watch "Submit to Same Page" New topic
Author

Submit to Same Page

Ramaswamy Srinivasan
Ranch Hand

Joined: Aug 31, 2004
Posts: 295
Hi Ranchers,

Well....plz clarify me this issue. I have a form, where i have certain fields and select their values. On submission, my requirement is to submit to the same form and display the selected values of the fields in a table. This shud happen iteratively, as the user wishes to select the values.

I intend of using avector to achieve this. I am successful partly in the sense that i am able to show one row. When i select the values for the next time, that existing row gets over-written. How to avoid this. I intend to show a row of selected details, each time i submit the fom.

Any help? Thanks in advance.

Cheers,
Swamy
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
i think its going perfectly fine. when you select some values then you should get all the records matching that particular criteria. and ofcourse the previously shown record not matching the new criteria would be ovewrwritten.

otherwise, please elaborate some more.
Ramaswamy Srinivasan
Ranch Hand

Joined: Aug 31, 2004
Posts: 295
Hi Adeel,

Thanks for ur reply. That's going fine. But according to the spec of my problem, the row should not be over-written. And moreover, the previous rows must be displayed, along with the same rows..Is there any way to do this? Any logic level change wud help this?

Do u think that i shud put my code too here....think it's pretty lengthy.

Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
you mean it should not be over written whether it is meeting the criteria or not. OK.

you should store all the rows in the request object using parameters. get all the parameters into a form bean then beans into any collection object, inside some of your handler class, then use
request.setAttribute("collection",collection).

it may help.

Note:
please dont go for request.setAttribute("anything", anything), cuz a different request object going to be created on your submit. i just mentioned this cuz its a common mistake some developer does.
Julian Kennedy
Ranch Hand

Joined: Aug 02, 2004
Posts: 823
Hi Swamy,

Am I right in thinking that you don't have a database or any persistent storage server-side? The user enters data, say at the top of the page, presses a button and you want it to be added to a list (table) at the bottom of the page, right?

I believe that the reason the data you submit gets overwritten is that you're only storing it in the request scope. If you want it to persist between requests you need to store it (your Vector) in the session scope, e.g. via HTTPSession.setAttribute(). Also, for best practice, use an ArrayList in preference to a Vector.

Jules
Ramaswamy Srinivasan
Ranch Hand

Joined: Aug 31, 2004
Posts: 295
Hi Julian,

Thanks, yar....

Actually, u r absalutely right in figuring out that there is no DB or persistant storage. I do need to show the records below, at a region in the same page. Anyway, could you give me some sample code or any reference to do it with Array List, Do I need to incorporate Session?

Thanks yar....

Cheers,
Swamy
Julian Kennedy
Ranch Hand

Joined: Aug 02, 2004
Posts: 823
Here's an ArrayList example from the Sun Collections Tutorial. You can get the HTTPSession by calling request.getSession() in your servlet.

You will learn better if you give this a go yourself. If you have any problems with the implementation you know where to come.

Jules
Ramaswamy Srinivasan
Ranch Hand

Joined: Aug 31, 2004
Posts: 295
Hi Jules,

Thanks a lot man.Got ur tip. Trying to work with it. Hope all goes fine.
Will get back to you if it works....

 
 
subject: Submit to Same Page