| Author |
Populating a drop down
|
Sudhir Pawar
Greenhorn
Joined: Sep 27, 2012
Posts: 22
|
|
|
how to populate select list with whole 1 column of table using jsp+servlet at onload event in jsp.
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56204
|
|
Why would you wait until the onload event? Simply create the element directly as HTML in the page.
|
[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
|
 |
Sean Rowlandson
Greenhorn
Joined: Jan 05, 2013
Posts: 4
|
|
Bear Bibeault wrote:Why would you wait until the onload event?  Simply create the element directly as HTML in the page.
This is a fair point however it depends on whether the contents of the table are known upon creation or whether the table is dynamically.
Can you explain your scenario a bit clearer and include details such as how and when the table you want the values from is populated?
Thanks
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56204
|
|
Sean Rowlandson wrote:
Bear Bibeault wrote:Why would you wait until the onload event?  Simply create the element directly as HTML in the page.
This is a fair point however it depends on whether the contents of the table are known upon creation or whether the table is dynamically.
It is highly unlikely that a database table depends upon a page loading. If so, then it's likely the data shouldn't be in the DB at all. The scenario makes no sense.
And yes, we need to hear from the OP regarding the scenario. I think it's likely that he's just overcomplicating what should be a simple and straightforward operation.
|
 |
Sean Rowlandson
Greenhorn
Joined: Jan 05, 2013
Posts: 4
|
|
Bear Bibeault wrote:
It is highly unlikely that a database table depends upon a page loading. If so, then it's likely the data shouldn't be in the DB at all. The scenario makes no sense..
Apologies, I was thinking of a html table however the post is unclear as to what is actually happening / what the desired outcome is.
|
 |
Sudhir Pawar
Greenhorn
Joined: Sep 27, 2012
Posts: 22
|
|
creation of select list is easy to create in html/jsp but from servlet how to populate it when page get loaded everytime???
|
 |
Albareto McKenzie
Ranch Hand
Joined: Apr 08, 2009
Posts: 268
|
|
|
If page gets fully loaded then you don't have a problem, just generate the list in the Servlet again, if you only want to change the dropdown on certain events then you have to use AJAX
|
 |
Sudhir Pawar
Greenhorn
Joined: Sep 27, 2012
Posts: 22
|
|
|
no AJAX. I want simple code for retrieving data using servlet from db and show it in select list in jsp when jsp page is opening(onload event).
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56204
|
|
My way:
The servlet calls responsible the model class, which returns the data.The servlet creates a Map where the key of each entry is the info that will become the value attribute of the options, and the value of the map entry is the display text, and places it in request scope.The JSP uses the JSTL <c:forEach> tag to iterate through the Map and generate the option elements.
Easy as pie.
|
 |
Albareto McKenzie
Ranch Hand
Joined: Apr 08, 2009
Posts: 268
|
|
Sudhir Pawar wrote:no AJAX. I want simple code for retrieving data using servlet from db and show it in select list in jsp when jsp page is opening(onload event).
Page is opening != onload event
Page is opening means that is not fully open yet, onload event is thrown when the html content is ready, why would you want to load all your html and after that make a request to get the values to populate the dropdown and not using AJAX? And more important than why, how would you do that without entering an endless loop?
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56204
|
|
|
Yes. See my previous post on how to so this in the JSP. The onload event is of no interest for this purpose.
|
 |
 |
|
|
subject: Populating a drop down
|
|
|