Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Populating drop-down box in JSP using bean

Status
Not open for further replies.

DKL01

Programmer
Sep 14, 2000
233
US
Hi,

I have a drop-down box in my JSP page and need to populate this control by the values returned
by method defined in bean class. I'm not sure about the syntax in JSP side. I really appreciate any suggestions.
Thanks


package business;

public class Common {
private String[] items = { "09/09/2002", "09/10/2002" , "09/11/2002" };


public String[] getPeriodEnding() {
return (items);
}

}
 
Unless you want lots of Java code in your JSPs, you need to develop an iterating tag. For example,

<select name=&quot;whatever&quot;>
<jsp:useBean id=&quot;newPeriod&quot; scope=&quot;session&quot;/>
<app:iterate id=&quot;thisPeriod&quot; array=&quot;newPeriod&quot;/>
<option><jsp:getProperty name=&quot;thisPeriod&quot; property=&quot;value&quot;/>
</app:iterate>
</select>

...to do that, you'd need to learn how to extend BodyTagSupport to build your own tags, and set up a TLD for your application. Short of that, the quick-n-dirty version would look something like this:


<select name=&quot;whatever&quot;>
<%
String[] period = getPeriodEnding();
for (int i = 0; i < period.length(); i++) {
%>
<option><%= period %>
<%
}
%>
</select>

Ian
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top