I am trying to use <html:form> tags with multiple text fields with the same name and getting the following error when accessing the form (index.jsp):
javax.servlet.ServletException: Exception thrown by getter for property: "cableCost[0]" of bean: "org.apache.struts.taglib.html.BEAN"
Here is my ActionForm code:
import org.apache.struts.action.ActionForm;
public class TestForm extends ActionForm
{
/**
* The unique id required by the serializable implementation.
*/
private static final long serialVersionUID = 1L;
private
String cableCost [];
/**
* @return Returns the cableCost.
*/
public String getCableCost(int index)
{
return cableCost[index];
}
/**
* @param cableCost The cableCost to set.
*/
public void setCableCost(int index,String cableCost)
{
this.cableCost[index] = cableCost;
}
}
Here is my Action Class:
public final class TestAction extends Action
{
public ActionForward execute(
ActionMapping mapping, ActionForm form,HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException
{
System.out.println("Start of
test Action");
String cableCost1 = ((TestForm) form).getCableCost(0);
String cableCost2 = ((TestForm) form).getCableCost(1);
String cableCost3 = ((TestForm) form).getCableCost(2);
System.out.println("Cable 1" + cableCost1);
System.out.println("Cable 2" + cableCost2);
System.out.println("Cable 3" + cableCost3);
return mapping.findForward("success");
}
}
Here is my form:
<%@ taglib uri="/WEB-INF/tlds/struts-html.tld" prefix="html" %>
<html:html>
<head>
<title>
Test Application
</title>
</head>
<body>
<html:form action="/test" method="post">
Cable Cost 1<html:text property="cableCost[0]" size="16"/><br />
Cable Cost 2: <html:text property="cableCost[1]" size="16"/><br />
Cable Cost 3: <html:text property="cableCost[2]" size="16"/><br />
<html:submit>
Submit
</html:submit>
</html:form>
</body>
</html:html>
Thanks for the help in advance,
Ollig