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 How to retain  the latest  selected value of drop down box. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Frameworks » Struts
Bookmark "How to retain  the latest  selected value of drop down box." Watch "How to retain  the latest  selected value of drop down box." New topic
Author

How to retain the latest selected value of drop down box.

pankaj semwal
Ranch Hand

Joined: Oct 07, 2008
Posts: 301
Hi,

how to retain the latest selected value of drop down box.
In my jsp page i have drop down box's which showing the dates.

I want if i selected day 30 then on the submit button and when the form reloads it should retain its latest selected value .i.e 31.

Please help me how to do it.

Below is my jsp page code:



Actionc class







thanks
Nishan Patel
Ranch Hand

Joined: Sep 07, 2008
Posts: 688


hi,

Just put at all your <s:select .../> box value tag. and that value equal to your <s:select .../> name tag.

Use


insted of

So, put just extra value tag at your select tag....



Thanks, Nishan Patel
SCJP 1.5, SCWCD 1.5, OCPJWSD Java Developer,My Blog
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

@Nishan: his select tags already *have* a "value" attribute set.

@Pankaj: I suspect the goal of your code is to display the current month/etc. on the first page view but the selected month/etc. on subsequent page views. Since you have a "value" attribute the select boxes will *always* show the current month/etc.

You can't have it both ways: if you use a "value" attribute that's the value that will be pre-selected. Another option would be to remove the "value" attribute and put the initial select value into the domain object (in your case the "employeetimesheetreport").

Two quick suggestions: use camel case for the domain object and its properties. "employeeTimeSheetReport.startMonth" is much easier to read than "employeetimesheetreport.startmonth". Also, spell "commonutil" correctly.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: How to retain the latest selected value of drop down box.