1

我对 struts 很陌生,而且我特别卡在与单选按钮有关的 struts 代码区域。无论我做什么,除了以下错误值外,我什么也得不到:(CostForm)

<td align="left" width="200px" colspan="2">
    <html:radio property="responsableBool" value="false"/>No
    <html:radio property="responsableBool" value="true"/>Yes
</td>

然后从这段代码初始化它:

CostForm costform = (CostForm) form;
Cost cost = new Cost();
costform.populateModel(cost);

而 populateModel 只是有:PropertyUtils.copyProperties(cost,this);

我唯一能想到的是struts不允许单选按钮引用具有不同值的相同属性。

4

1 回答 1

0

给定形式:

public class CostForm extends ActionForm {
    private boolean responsableBool; // And getter/setter
}

的HTML:

<html:form action="/costsub">
    <html:radio property="responsableBool" value="false"/>No
    <html:radio property="responsableBool" value="true"/>Yes
    <html:submit/>
</html:form>

那个行动:

public ActionForward execute([args elided]) throws Exception {
    CostForm costForm = (CostForm) form;
    System.out.println(costForm.isResponsableBool());
    // etc.

当我单击“否”和“是”时,我会在操作中得到预期的布尔值。

I'd double-check things like spelling (the English spelling would be "responsible"; perhaps it's spelled correctly in Cost?), action/form mismatches (are you using the right form "name" in the action mapping?), and so on.

于 2011-10-08T12:08:46.533 回答