继续获取OgnlException:getProperty的source为null(null," 0")警告

时间:2014-05-16 21:29:57

标签: java-ee struts2 ognl

确定。所以我使用下面的.jsp和Java代码来访问notMessageFieldList。它工作正常;但是,当我离开页面时,我一直收到OgnlException: source is null for getProperty(null, "0"}警告。 Struts 2似乎试图获取 null 值并触发此警告。有没有办法摆脱它而不调整我的Tomcat设置?

JSP:

        <s:iterator var="counter" begin="0" end="3">
        <tr>
            <th style="font-size: 120%; font-weight: 900; color: red;">X</th>
            <td style="font-size: 80%;">NEW</td>
        </tr>
        <tr>
            <td><b>Field Name:</b>&nbsp;
            </td>
            <td style="float: left">
                <s:textfield
                        name="notMessageFieldList[%{counter}].tag"
                        size="47">
                </s:textfield>
            </td>
        </tr>
        <tr>
            <td><b>Description:</b>&nbsp;
            </td>
            <td style="float: left">
                <s:textfield
                        name="notMessageFieldList[%{counter}].description"
                        size="47">
                </s:textfield>
            </td>
        </tr>
        <tr>
            <td><b>Data Type:</b>&nbsp;
            </td>
            <td style="float: left">
                <s:select
                        list="validDataTypes"
                        name="notMessageFieldList[%{counter}].dataType"
                        key="dataType.required"/>
            </td>
        </tr>
        </s:iterator>

JAVA行动:

private List<NotificationMessageField> notMessageFieldList = new ArrayList<>(4);

public List<NotificationMessageField> getNotMessageFieldList() {
        return notMessageFieldList;
    }

public void setNotMessageFieldList(@Nullable final List<NotificationMessageField> notMessageFieldList) {
    if (CollectionUtils.isNotEmptyList(notMessageFieldList)) {
        this.notMessageFieldList.clear();
        this.notMessageFieldList = new ArrayList<>(notMessageFieldList);
    } else {
        this.notMessageFieldList = new ArrayList<>(5);
    }
}

JAVA POJO(假设定期设置,getter / setter):

public NotificationMessageField(final String tag, final String description, final String dataType) {
    this.tag = tag;
    this.description = description;
    this.dataType = dataType;
}

1 个答案:

答案 0 :(得分:1)

将value属性添加到textfields。它将使用初始值预设文本字段,一旦预设值,就不会通过名称对其进行评估。

<s:textfield name="notMessageFieldList[%{counter}].tag" size="47" value="">