Hi All,
I am new to
Struts. I need your help.
I need to display a list of values in selected tag. The values are from a Form Bean. I am able to display two other columns correctly, but i am getting confused using the selected field. I am adding the coding part here. Please help me in correcly using the Selected tag.
Action Form class
===============================
package code;
import java.util.ArrayList;
import javax.servlet.http.HttpServletRequest;
import org.apache.struts.action.ActionError;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
public final class LoginForm extends ActionForm {
private
String name = null;
private String pwd = null;
private ArrayList coll1 = null;
private String action = "Set";
public void setName(String name) {
System.out.println("form setName " + name);
this.name = name;
}
public String getName() {
System.out.println("form getName " + name);
return name;
}
public void setPwd(String pwd) {
System.out.println("form setPwd " + pwd);
this.pwd = pwd;
}
public String getPwd() {
System.out.println("form getPwd " + this.pwd);
return pwd;
}
public void setColl(ArrayList coll) {
this.coll1 = coll;
}
public ArrayList getColl() {
return coll1;
}
}
===============================
Out Put
JSP:
===============================
<%@ taglib uri="/WEB-INF/app.tld" prefix="app"%>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html"%>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic"%>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean"%>
<%@ page import="code.LoginForm"%>
<html:html>
<head>
<title>
Success!!!
</title>
</head>
<body>
<font color="blue">
Name:
<bean:write name="loginForm" property="name"/>
<br><br>
Password:
<bean:write name="loginForm" property="pwd"/>
<br><br>
<html:select name="loginForm" property="coll">
<html
ptions collection="coll1" property="coll" labelProperty="coll"/>
</html:select>
</font>
</body>
</html:html>
===============================