0

What is the OGNL syntax for accessing an indexed list where the contents of the list is an inner class. Google gives a couple of examples but these are related to accessing static members of an inner class or ENUMS.

My action class

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;
        }
}

and the relevant part of the jsp page

<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>

The page displays correctly and when the update is called, I can see getRows() called correctly, but the setters on the inner class are never called. If I move my inner class Row to it's own top level class then the standard

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

works correctly.

Andrea Ligios
  • 49,480
  • 26
  • 114
  • 243
user497087
  • 1,561
  • 3
  • 24
  • 41

0 Answers0