File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Show the selected value in dropdown again

 
thomas colding
Ranch Hand
Posts: 60
  • 0
  • Mark post as helpful
  • send pies
  • 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
 
manoj r patil
Ranch Hand
Posts: 181
  • 0
  • Mark post as helpful
  • send pies
  • 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: 60
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64173
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Same way. Whatever option has the selected attribute will be the selected option.
 
thomas colding
Ranch Hand
Posts: 60
  • 0
  • Mark post as helpful
  • send pies
  • 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?
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thomas colding wrote:

response.setRenderParameter("montno",sSearchString);



why?
 
Salil Vverma
Ranch Hand
Posts: 255
Hibernate Oracle Spring
  • 0
  • Mark post as helpful
  • send pies
  • 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
Author and ninkuma
Marshal
Pie
Posts: 64173
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
Paul Clapham
Sheriff
Pie
Posts: 20166
24
MySQL Database
  • 0
  • Mark post as helpful
  • send pies
  • 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: 60
  • 0
  • Mark post as helpful
  • send pies
  • 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
Author and ninkuma
Marshal
Pie
Posts: 64173
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bingo.
 
thomas colding
Ranch Hand
Posts: 60
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:Bingo.

Sorry but as I mentioned I am Newbie and not used to develop Webapplications.
 
suchit pandya
Ranch Hand
Posts: 43
  • 0
  • Mark post as helpful
  • send pies
  • 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: 60
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the input.
 
Salil Vverma
Ranch Hand
Posts: 255
Hibernate Oracle Spring
  • 0
  • Mark post as helpful
  • send pies
  • 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: 60
  • 0
  • Mark post as helpful
  • send pies
  • 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
Author and ninkuma
Marshal
Pie
Posts: 64173
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • 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
Pie
Posts: 20166
24
MySQL Database
  • 0
  • Mark post as helpful
  • send pies
  • 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: 60
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic