aspose file tools*
The moose likes JSP and the fly likes JSP drop downs 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 "JSP drop downs" Watch "JSP drop downs" New topic
Author

JSP drop downs

vikas Gourishetty
Ranch Hand

Joined: Aug 20, 2010
Posts: 38
Hi all,

I need a suggestion for the following:


I am designing a couple of JSP pages.

In JSP1, I have 2 drop down boxes and a submit button.

[After User selects the values in drop down boxes, and click submit It gets saved to database and method returns 'SUCCESS' or 'FAIL'. ]

If it is SUCCESS it will go to another view JSP2.

If it happens to be FAIL, then the I should display the JSP1 with the drop down box values what ever the user selected !!

Can any one help me to attack this problem. Thank you very much.




Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61043
    
  66

Place the selected attribute on the <option> element that you wish to be selected.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
vikas Gourishetty
Ranch Hand

Joined: Aug 20, 2010
Posts: 38
Hi Bear,

Thank you very much for replying.

In my jsp page I have used the following code:





For the first time, The drop down list shows Select Study Action.

In case of failure (on clicking submit), suppose if the user clicks "Read" option, when the page reloads, I want to display "Read" instead of the default value !!


Please suggest.



Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61043
    
  66

Already answered:
Bear Bibeault wrote:Place the selected attribute on the <option> element that you wish to be selected.
vikas Gourishetty
Ranch Hand

Joined: Aug 20, 2010
Posts: 38
Can you be a little more clear.

Thanks,

-Vikas
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61043
    
  66

Within your loop, determine which option element has the value that matches the one that you want to be selected, and place the selected attribute on that option element.

No, I will not write the code for you, but will give you the hint that, when I do this, I find that the EL ternary operator (?) is very useful.
vikas Gourishetty
Ranch Hand

Joined: Aug 20, 2010
Posts: 38
Bear,

My point of interest is:

To determine what value the user has selected previously from the drop down, How can we know that?

I am sorry, I did not not mean to get any sort of code from you.


Thanks,

-Vikas
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61043
    
  66

It will have been submitted as part of the original request, no? You'll need to make that value available to the next request so that it can be used to determine which option to mark as selected.

That can be done by storing it in the session (be sure to clear it out hen no longer needed), or passed as a request parameter on the redirect URL.
vikas Gourishetty
Ranch Hand

Joined: Aug 20, 2010
Posts: 38
Thank you Bear. Conversation with you did help me out.

Thank you very much.

-Vikas
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: JSP drop downs