索引内部类的OGNL语法

时间:2014-10-13 08:42:49

标签: java jsp struts2 inner-classes ognl

用于访问索引列表的OGNL语法是什么,其中列表的内容是内部类。 Google提供了几个示例,但这些示例与访问内部类或ENUMS的静态成员有关。

我的动作类

public class EditNanocomUnlockCode extends ActionSupport {


private static final long serialVersionUID = -242116564326058998L;

private int id;
private int unlockCode;
private String description;
private List<Row> rows = new ArrayList<Row>();
private NanocomUnlockCode code;

@Autowired
NanocomUnlockCodeService service;



public String execute() {

    NanocomUnlockCode code = service.find(id);
    if (code == null) {
        throw new IllegalArgumentException("Trying to access an unknown unlock code " + id);
    }

    unlockCode = code.getUnlockCode();
    description = code.getName();
    for(Integer platformId: code.getPlatformIds()) {
        addRow(platformId, Services.getPlatform(platformId).getPlatformName());
    }
    return SUCCESS;
}


private void addRow(int platformId, String platformName) {
    rows.add(new Row(platformId, platformName));

}


public int getId() {
    return id;
}

public void setId(int id) {
    this.id = id;
}


public int getUnlockCode() {
    return unlockCode;
}


public void setUnlockCode(int unlockCode) {
    this.unlockCode = unlockCode;
}


public String getDescription() {
    return description;
}


public void setDescription(String description) {
    this.description = description;
}





public NanocomUnlockCode getCode() {
    return code;
}


public void setCode(NanocomUnlockCode code) {
    this.code = code;
}


public List<Row> getRows() {
    return rows;
}

public void setRows(List<Row> rows) {
    this.rows = rows;
}


    public class Row {

        private boolean selected = false;
        private Integer platformId;
        private String description;

        public Row(Integer platformId, String description) {
            this.selected = false;
            this.platformId = platformId;
            this.description = description;
        }

        public Row() {
            this.selected = false;
        }

        public boolean isSelected() {
            return selected;
        }

        public void setSelected(boolean selected) {
            this.selected = selected;
        }

        public Integer getPlatformId() {
            return platformId;
        }

        public void setPlatformId(Integer platformId) {
            this.platformId = platformId;
        }

        public String getDescription() {
            return description;
        }

        public void setDescription(String description) {
            this.description = description;
        }
}

和jsp页面的相关部分

<s:form action="update-nanocom-unlock-codes" theme="simple">
<s:iterator value="rows" status="status">

    <tr>
    <td>

        <s:checkbox name="rows[%{#status.index}].selected" value="%{com.blackbox.x.actions.admin.EditNanocomUnlockCode.rows[#status.index]$Row.selected}"/>
    </td>
    <td>
        <s:label value= "%{rows[#status.index].description}"/>
    </td>    
    </tr>
</s:iterator>
</s:form>

页面显示正确,当调用更新时,我可以看到正确调用了getRows(),但是从不调用内部类的setter。如果我将我的内部类Row移动到它自己的顶级类,那么标准

<s:checkbox name="rows[%{#status.index}].selected" value="%{rows[#status.index].selected}"/>

正常工作。

0 个答案:

没有答案