【问题标题】:Keep getting the OgnlException: source is null for getProperty(null, "0") Warning继续收到 OgnlException: source is null for getProperty(null, "0") 警告
【发布时间】:2014-05-16 21:29:56
【问题描述】:

好的。所以我使用下面的 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;
}

【问题讨论】:

    标签: jsp struts2 ognl


    【解决方案1】:

    将 value 属性添加到文本字段。它将使用初始值预设文本字段,并且一旦预设值,它将不会按名称进行评估。

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

    【讨论】:

    • @Roman C:感谢您的尝试,但它仍然抛出警告。我将不得不继续“摆弄”它。幸运的是,它并没有抛出一个完整的错误并停止应用程序,它只是抛出了一堆警告。 . .这让我有更多的时间深入了解。
    • @Mike 您可以发布警告,但如果是相同的警告,则无法解决。根据您提供的信息,无法告诉您为什么会发生这种情况。我可以建议您在属性notMessageFieldList 上调试问题并检查它未初始化的位置。
    猜你喜欢
    • 2013-11-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-15
    • 2016-06-30
    • 1970-01-01
    相关资源
    最近更新 更多