I keep getting errors trying to do html:select/html:options in a form. I'm not understanding how to code the tag, whether with property or collection attributes and how the interaction works with the Action class and the struts-config.xml. Can someone show me the syntax for all three files, please? I'm looking for a simple implementation. Here is what I've got:
JSP------------
<%@ page import="java.sql.*"%>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html"%>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean"%>
<html>
<head></head>
<body>
<html:form action="/select">
<html:select property="select" >
<html:options property="names" />
</html:select>
</html:form>
</body>
</html>
STRUTS-CONFIG.XML---------------------
...
<form-beans>
<form-bean name="selectForm" type="com.test.struts.form.SelectForm">
<form-property name="select" />
<form-property name="names" type="java.lang.String" />
</form-bean>
</form-beans>
...
SELECTACTION.JAVA----------------------
try{
SelectForm selectForm = (SelectForm) form;
DataSource ds = (DataSource )servlet.getServletContext().getAttribute(Action.DATA_SOURCE_KEY);
Connection con = ds.getConnection();
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("select LAST_NM from MY_TBL");
ArrayList arrayList= new ArrayList();
while(rs.next())
{
arrayList.add(new org.apache.struts.util.LabelValueBean(rs.getString(1)));
}
selectForm.setNames(al);
request.getSession().setAttribute("names", al);
SELECTFORM.JAVA---------------------
public class SelectForm extends ActionForm {
private
String select;
private String names;
public String getSelect() { return select; }
public void setSelect(String select) { this.select = select; }
public String getNames() { return names; }
public void setNames(String names) { this.names= names; }
}