Search code examples
javajspstrutsstruts-1html

Can't access a property with <html:checkbox property="..."> when iterating a list


In my Struts form I've got a list. In a JSP I iterate over it like this:

<c:forEach items="${MyForm.types}" var="type">
    <tr>
        <td>${type.name}</td>
        <td>${type.forced}</td>
        <td>${type.receive}</td>
        <html:checkbox property="type.receive" />
    </tr>
</c:forEach>

Now the <html:checkbox isn't working. I'm always getting the following error:

Caused by: javax.servlet.jsp.JspException: No getter method for property type.receive of bean org.apache.struts.taglib.html.BEAN

But actually there is a getter for this property in my form class. It's written like this:

public Boolean getReceive() {
  return receive;
}

When I remove the checkbox it's also possible to display the property as in the <td>-tag above so I don't know where the problem is.

Maybe I'm accessing it in the wrong way?


Solution

  • I'm now doing it like this:

    <c:forEach items="${MyForm.testList}" var="testElement" varStatus="status">
        <html:checkbox property="testList[${status.count-1}].checkboxValue" />
    </c:forEach>
    

    Thanks to this question.