This week's book giveaway is in the Cloud/Virtualizaton forum.
We're giving away four copies of Mesos in Action and have Roger Ignazio on-line!
See this thread for details.
Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JSP drop downs

 
vikas Gourishetty
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64833
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Place the selected attribute on the <option> element that you wish to be selected.
 
vikas Gourishetty
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64833
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Already answered:
Bear Bibeault wrote:Place the selected attribute on the <option> element that you wish to be selected.
 
vikas Gourishetty
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you be a little more clear.

Thanks,

-Vikas
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64833
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64833
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic