Can I make a dynamic list box from DB results

M

mike.a.rea

I have a JSP page that returns a set of several different values from a
db table. I can show these in tabular format without a problem.

However I was wondering if there was a way that I could use the
information in a drop down list box, maybe use one variable as the Item
Label and another one as the Value.

Any ideas on how I can do this? Thanks in advance.
 
D

ducnbyu

I have a JSP page that returns a set of several different values from a
db table. I can show these in tabular format without a problem.

However I was wondering if there was a way that I could use the
information in a drop down list box, maybe use one variable as the Item
Label and another one as the Value.

Any ideas on how I can do this? Thanks in advance.

Try:

<html:select property="selectField">
<html:eek:ption value="-- Select One --"/>
<html:eek:ptionsCollection property="table" label="name" value="code" />
</html:select>

In your form (java) class you probably already have a collection that
you use to display the table. In my example (note the capitalization),
the class in the collection would have getName() and getCode() methods.
 
O

Oliver Wong

I have a JSP page that returns a set of several different values from a
db table. I can show these in tabular format without a problem.

However I was wondering if there was a way that I could use the
information in a drop down list box, maybe use one variable as the Item
Label and another one as the Value.

Any ideas on how I can do this? Thanks in advance.

If you know how to do this in a tabular format, presumably, you have code
which emits something like:

<table>
<tr><td>VALUE A</td></tr>
<tr><td>VALUE B</td></tr>
</table>

So change your code so that it instead outputs:

<select>
<option>VALUE A</option>
<option>VALUE B</option>
</select>

As for the issue of using a label versus a value, the value attribute has no
equivalent in a table, so I'm not sure what you intend to do there.

- Oliver
 
M

mike.a.rea

Ok thanks, this is the road I was going down, just haven't got it to
work yet.
No there is no equivalent the the Value attribute in the table.
However I have several different data fields being returned from the
data table for each record, I just want to show one field to the end
user and pull another to pass along to the next application.
Thanks again, I will keep working on it.
 
M

mike.a.rea

Ok thanks, this is the road I was going down, just haven't got it to
work yet.
No there is no equivalent the the Value attribute in the table.
However I have several different data fields being returned from the
data table for each record, I just want to show one field to the end
user and pull another to pass along to the next application.
Thanks again, I will keep working on it.
 
L

Lew

Try:

<html:select property="selectField">
<html:eek:ption value="-- Select One --"/>
<html:eek:ptionsCollection property="table" label="name" value="code" />
</html:select>

In your form (java) class you probably already have a collection that
you use to display the table. In my example (note the capitalization),
the class in the collection would have getName() and getCode() methods.

The OP did not state that he was using Struts. For these constructs I would
prefer JSTL (e.g., <c:forEach>)even if I were using Struts.

- Lew
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top