Please consider taking at look at the following query I have to create and put in my JSP page's <select><option value=""></option></select> portion...
SELECT department_id, department_name FROM departments_tbl;
this would give me more than 1 result... I was wondering if I should create a servlet that returns Vector/ArrayList... Or a bean that has a get method that returns a vector? I'm a little confused... I've already been working overnight... I probably even sound senseless to you guys...
Select options usually have two elements: a value and display text:
such as the id and name that you are getting from your query.
Whenever I have to get select options from a database, I create a model class (a class which has no knowledge whatsoever of what kind of UI the program has) that returns a List of elements. Since each element needs two values, I created a class that implements the Map.Entry interface, and populate each one of these with the option value (as the Map.Entry key) and the option display text (as the Map.Entry value) before placing it in the List.
My controller servlet will call this model class to get the List of these elements, which it places on the request as a scoped variable. The JSP page then can use the JSTL and EL to construct the select element from the List (actually I do this so often I wrote a custom action to do it for me). [ January 13, 2006: Message edited by: Bear Bibeault ]
Hi Bear... Thanks! I understand you might be trying to make me learn by myself by allowing me to research on my own... I think I have quite understood your point... But there are still some things in Java that I actually am not well aware of such Map.Entry and I don't know if I have the time to learn it on my own. So far I am familliar with Vector, ArrayList and HashTable... I haven't even used a map yet... I would really appreciate if you could pull me off some code that demonstrate how I could use it with an option tag. Thanks a lot for your help man. And sorry for the bother...
P.S. I'm trying meet the deadline for my project... And I'm no student so you won't have to worry. [ January 13, 2006: Message edited by: Timothy Sam ]
I'm more than willing to help you write your own code, but I cannot write the code for you. If implementing a simple interface like Map.Entry has you spooked, you can create your own class from scratch that contains the two values to put into the List. And you have already stated that you are familiar with ArrayList, so I believe you have all the tools you need at your disposal to tackle this task.
Give it a shot and check back with any brick walls that you might hit.