This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes Struts and the fly likes saving preselected drop down value Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Frameworks » Struts
Bookmark "saving preselected drop down value" Watch "saving preselected drop down value" New topic
Author

saving preselected drop down value

divya kundapur
Ranch Hand

Joined: Aug 21, 2007
Posts: 110
I have 2 drop down lists, once the user selects the first drop down it gets the list values of second drop down. But i need to save the values selected by the user from the 2 drop down lists when the page reloads and i m thinking of using session. Any help is appreciated.


SCJP - 5.0
Pravin Shirke
Ranch Hand

Joined: Apr 05, 2008
Posts: 150

hii divya,
not clear what is happening can you please elaborate it a bit.
thank you.


[Vipassana] - It is seeing the reality as it is, And not as you want it to be.!!!
SCJP1.5.
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9303
    
  17

If you are talking about page refresh, then you cannot control that using session on the server unless you use some sort of AJAX to send the currently selected drop down to the server. I had this kind of situation once and I used javascript to store the currently selected drop down as a hash in the URL. in the onLoad event of body tag, I called a method which extracted the value from the hash and pre-selected the drop down.

It goes something like this



SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
gurneeraj singh
Ranch Hand

Joined: Mar 19, 2008
Posts: 80
Can't we use custom tags for this functionality?


SCJP 5.0 93%<br /> <br />SCWCD 5.0 97 %
divya kundapur
Ranch Hand

Joined: Aug 21, 2007
Posts: 110

I want to use sessions to save drop down selected value and i have 2 drop down lists. Any help is appreciated.
Thanks
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61315
    
  66

That's pretty straight-forward. Save the selection values in the session as scoped variables, then use JSP mechanisms on the page to set the selected attribute on the appropriate <option> elements. What part are you having problems with?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
divya kundapur
Ranch Hand

Joined: Aug 21, 2007
Posts: 110
so i just need to have 2 session.setAttributes for 2 drop down lists, then in the struts action class access them, then how shall i add them in the options tag in jsp , since the inital value is set like this

<option value="0">
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61315
    
  66

As you are using Struts, I've moved this to the Struts forum for any further discussion.
 
 
subject: saving preselected drop down value