• 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
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Show the selected value in dropdown again

 
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a JSP Page with a drop down select boxes that is used to make a search.

My challenge is to show the same value as selected in the Dropdown when the search result is returned.


My Dropdown is builds as following on my JSP Page

<SELECT name="montno" onChange="selectChanged(this);">
<OPTION value="1" selected>1</OPTION>
<OPTION value=2>2</OPTION>
<OPTION value=3>3</OPTION>
<OPTION value=4>4</OPTION>
<OPTION value=5>5</OPTION>
<OPTION value=6>6</OPTION>
<OPTION value=7>7</OPTION>
</SELECT>




In procesaction I retrieve the selected values from the hidden field I have added the selected values to.

String sSearchString = request.getParameter("numberoffmonth");


Then I Add it to the response to retrieve it in Process view

response.setRenderParameter("montno",sSearchString);



What do I have to do so it is selected value when the JSP is visible again.?

Thanks
 
Ranch Hand
Posts: 182
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think you can set the "selected" in the following code dynamically while returning the dropdown list?



...or am I missing something?
 
thomas colding
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

mannoj patil wrote:I think you can set the "selected" in the following code dynamically while returning the dropdown list?



...or am I missing something?




What do you mean , if you see in the above html code, it is alreadey selected.
Bu my challenge is how to show value the User has selected afte the Search result is returned.
 
Sheriff
Posts: 67753
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
Same way. Whatever option has the selected attribute will be the selected option.
 
thomas colding
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bear Bibeault wrote:Same way. Whatever option has the selected attribute will be the selected option.



Could you please specify what you mean, is it possible?
 
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

thomas colding wrote:

response.setRenderParameter("montno",sSearchString);



why?
 
Ranch Hand
Posts: 257
Hibernate Oracle Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What is the purpose of following function

I could not find this function as a part of javax.servlet.http.HttpServletResponse in j2ee 5.p api library

 
Bear Bibeault
Sheriff
Posts: 67753
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

thomas colding wrote:

Bear Bibeault wrote:Same way. Whatever option has the selected attribute will be the selected option.



Could you please specify what you mean, is it possible?


I'm not sure how I could possibly make it more clear.

Whatever option you put the selected attribute on will be the selected option. This is just basic HTML.
 
Sheriff
Posts: 28362
99
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bear Bibeault wrote:This is just basic HTML.



That's the key thing to understand. To answer your question there are two steps:

(1) Figure out what HTML you want the browser to get.

(2) Write your JSP to produce that HTML.

You don't seem to have done step (1) properly. And then if you don't know what HTML you want to produce, it's hard to write code to produce it.
 
thomas colding
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It sound after all the input that I have to built the Dropdown list dynamically and set the value that the user has selected at default
 
Bear Bibeault
Sheriff
Posts: 67753
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
Bingo.
 
thomas colding
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bear Bibeault wrote:Bingo.


Sorry but as I mentioned I am Newbie and not used to develop Webapplications.
 
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
if you can use java script on page then you can do below code.

also store selected value in request and after when page loads back retrive both the values.

 
thomas colding
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the input.
 
Salil Vverma
Ranch Hand
Posts: 257
Hibernate Oracle Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey suchit,

Implementing this in jsp using el or scriptlet would be better option than implementing this in java script due to following to reasons -
1- If java script is disabled in browser, this functionality would not work
2-it would require some additional data to be sent to the browser resulting in performance hit.

 
thomas colding
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

Would it be better approach to build the dropdown content in java process action, and then transfer it to the JSP-page.
A dynamical list.
 
Bear Bibeault
Sheriff
Posts: 67753
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
No. Just use JSP conditional mechanisms to set the selected attribute on the right option. This is done all the time.

What part are you having trouble wrapping your mind around? What the HTML should look like, or how to write JSP expressions to create that HTML?
 
Paul Clapham
Sheriff
Posts: 28362
99
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
From what I can see, at least from the original post, Thomas already has JSP code which generates the SELECT element. All that's needed is to improve that to add the "selected" attribute on the appropriate OPTION element. Perhaps the question is how to do that; I can see that being a FAQ. I know I had trouble figuring out a way to do that in the EL.
 
thomas colding
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Paul Clapham wrote:From what I can see, at least from the original post, Thomas already has JSP code which generates the SELECT element. All that's needed is to improve that to add the "selected" attribute on the appropriate OPTION element. Perhaps the question is how to do that; I can see that being a FAQ. I know I had trouble figuring out a way to do that in the EL.




Exactly what I had in the mind, they must be some off you that may have create a Drowdown in which you select a value. submit the form.
And when they JSP is visible again with a result, the last selected value should be the one should as default selected in the dropdown.
So at least it is possible to what the result was based on.
 
I'm a lumberjack and I'm okay, I sleep all night and work all day. Lumberjack ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic