• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

JSP drop downs

 
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.




 
Sheriff
Posts: 67756
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Sheriff
Posts: 67756
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can you be a little more clear.

Thanks,

-Vikas
 
Bear Bibeault
Sheriff
Posts: 67756
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Sheriff
Posts: 67756
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you Bear. Conversation with you did help me out.

Thank you very much.

-Vikas
 
And will you succeed? Yes you will indeed! (98 and 3/4 % guaranteed) - Seuss. tiny ad:
Clean our rivers and oceans from home
https://www.kickstarter.com/projects/paulwheaton/willow-feeders
reply
    Bookmark Topic Watch Topic
  • New Topic