views:

47

answers:

4

Hi.

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

<c:forEach items="${MyForm.auspraegungen}" var="auspraegung">
    <tr>
        <td>${auspraegung.name}</td>
        <td>${auspraegung.forced}</td>
        <td>${auspraegung.cbx_uebernehmen}</td>
        <html:checkbox property="auspraegung.cbx_uebernehmen" />
    </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 auspraegung.cbx_uebernehmen 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 getCbx_uebernehmen() {
  return cbx_uebernehmen;
}

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?

A: 

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

No, I don't think so. I'm already using a `<html:radio>`-tag with a boolean property and it works. See http://struts.apache.org/1.2.7/userGuide/struts-html.html#checkbox for more information ("[...] The underlying property value associated with this field should be of type boolean [...]").
Bernhard V
This is certainly incorrect advice. Action form can contain variables of types other than String.
Tommi
A: 

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.

Tommi
It's a `Boolean` property, not `boolean`. Regardless, the Javabean spec allows both, it would have been a bug in Struts otherwise.
BalusC
Yep, didn't think it would really make any difference either, but just thought it could be worth a try if it still didn't work for some reason. I think the problem is because of the naming.
Tommi
Hm, then again, Struts user guide (linked by Bernhard V in his comment to another answer) does state "The underlying property value associated with this field should be of type **boolean**."
Tommi
It didn't work with boolean from the beginning, so I switched to Boolean. Nevertheless, in the same form there is a Boolean property which I can use without a problem in a `<html:checkbox>`. It also has a "get"-getter.
Bernhard V
A: 

Try changing your html:checkbox tag to the following:-

<html:checkbox name="auspraegung" property="cbx_uebernehmen" />
limc
A: 

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.

Bernhard V