开发者

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

开发者 https://www.devze.com 2023-01-04 00:11 出处:网络
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\">

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.r开发者_StackOverflow社区eceive" />
    </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?


All the individual properties type in struts Action form should be String.You have to define cbx_uebernehmen as String Type.


I think your getter method should look like this (is... instead of get...) :

public Boolean isCbx_uebernehmen() {
  return cbx_uebernehmen;
}

Should work like that. If it still doesn't, try changing return datatype from Boolean to boolean.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消