wood burning stoves 2.0*
The moose likes Struts and the fly likes How to retaining form values for multiple submit? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "How to retaining form values for multiple submit?" Watch "How to retaining form values for multiple submit?" New topic
Author

How to retaining form values for multiple submit?

Udhayha Dhayalan
Greenhorn

Joined: Dec 05, 2013
Posts: 8
I am using struts1. I have a jsp with 7 dependant dropdowns. Each dropdown change submits the form and populates the next. I need to hold all dropdown values values each time it is submitted. When I use session=scope in struts-config everything is working fine. But the values in my page remain the same even when navigated to other pages and coming back.
I need to either retain values in request somehow
or
I need to clear all values in session when leaving page

Is there some way of doing this??
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8836
    
    7

Welcome to the JavaRanch.

Udhayha Dhayalan wrote:I am using struts1.


If it is at all possible, please do not.

Udhayha Dhayalan wrote:
I need to clear all values in session when leaving page


You can clear the session values in your action. You will also probably also have to prevent the browser from caching the values (see here)


"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
Udhayha Dhayalan
Greenhorn

Joined: Dec 05, 2013
Posts: 8
Joe Ess wrote:If it is at all possible, please do not.

We are towards end of work. We have no way out

Joe Ess wrote:
You can clear the session values in your action. You will also probably also have to prevent the browser from caching the values (see here)


First, I need to detect when leaving the page only then I can clear session.
So, any idea how to detect that using javascript?
Please note that I have multiple submits in the same jsp page. So I cannot use window.unload function()
If Im going for session scope, the session has to be populated across all submits until I leave the page.
How can I do this?

Or is there a way to retain values in request?? Anuything is fine...
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8836
    
    7

Udhayha Dhayalan wrote:
First, I need to detect when leaving the page only then I can clear session.


The last submit is the only one with the last field filled in, right?

Udhayha Dhayalan wrote:
Please note that I have multiple submits in the same jsp page. So I cannot use window.unload function()


You seem to be thinking client JavaScript, rather than Struts action.

Udhayha Dhayalan wrote:
If Im going for session scope, the session has to be populated across all submits until I leave the page.


I'm not sure what you are saying here. Sessions can last for multiple submits and once a value is placed in one, it's there. It doesn't need to be reset.
Udhayha Dhayalan
Greenhorn

Joined: Dec 05, 2013
Posts: 8
The last submit is not the last dropdown I have a search and save button after that...
My functionality is like this
1)We have 7 filters on top
2)When all 7 are selected user can click on search to view related data in a table
3)User can also fill in details in the table and save
So each of them is a form submit and we can never say which is the last.
The user can save how many ever times.
This is only one of the webpages of our site.
Right now we are working on session scope so it is working fine.
But we want it on request. So that the page gets cleared when moved to diffenernt page and opens blank everytime page is entered.

I dont think session is the right choice.
I somehow want to retain values on request scope... Is it possible?
I have tried request.setAttribute("formName",formName); everytime form is submitted.
It is not working Any idea what can be done?
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8836
    
    7

Udhayha Dhayalan wrote:
I somehow want to retain values on request scope... Is it possible?
I have tried request.setAttribute("formName",formName); everytime form is submitted.
It is not working Any idea what can be done?


Of course. You should be setting the values on the form object rather than the request.
If I had a requirement like this, I'd probably use Ajax requests to implement the dependent drop-down fields an separate the function of building the request from saving it.
 
Don't get me started about those stupid light bulbs.
 
subject: How to retaining form values for multiple submit?
 
Similar Threads
Problems with Action Errors in Struts
Dropdown Selected returning unexpected value on submit.
Retaining javascript values in jsp
list box problem
clear session scoped variable values