-2

am having the following jsp tag to display arraylist values.whereas the zoneInformation contains [North, South, East, West].

<html:form action="addcountry">
<%@ page import="java.util.List"%>
<%@ page import="java.util.ArrayList"%>
<html:select property="zone" styleClass="text ui-widget-content ui-corner-all">     
<%  ArrayList ls = (ArrayList)request.getAttribute("zoneInformation");
for(int i=0;i<ls.size();i++){
%>
<html:option value=" "><%=ls.get(i)%></html:option> 
<%}%>
</html:select>
</html:form>

how to set values to this dropdown list....?

Bozho
  • 588,226
  • 146
  • 1,060
  • 1,140

2 Answers2

0

First, prefer JSTL: c:forEach instead of scrptlets.

Then, you can just set the value to be the same as the displayed label.

Then, you can use <html:options collection="${zoneInformation} /> without any loop.

Bozho
  • 588,226
  • 146
  • 1,060
  • 1,140
0

The html:select tag will make the option with the same value as its property attribute value selected automatically. So, in your code, the zone information with the value " " will be selected. This means that if you want some option selected, its value should be equal to the zone property of the form bean.

And please, don't use scriptlets. Use the JSTL and the EL.

JB Nizet
  • 678,734
  • 91
  • 1,224
  • 1,255