Reputation: 1610
Ok. So I am using the below JSP and Java code to access the notMessageFieldList
. It works fine, however, I keep getting a OgnlException: source is null for getProperty(null, "0")
warning when I leave the page. It seems that Struts 2 is trying to get null values and triggers this warning. Is there any way to get rid of it without adjusting my Tomcat settings?
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>
</td>
<td style="float: left">
<s:textfield
name="notMessageFieldList[%{counter}].tag"
size="47">
</s:textfield>
</td>
</tr>
<tr>
<td><b>Description:</b>
</td>
<td style="float: left">
<s:textfield
name="notMessageFieldList[%{counter}].description"
size="47">
</s:textfield>
</td>
</tr>
<tr>
<td><b>Data Type:</b>
</td>
<td style="float: left">
<s:select
list="validDataTypes"
name="notMessageFieldList[%{counter}].dataType"
key="dataType.required"/>
</td>
</tr>
</s:iterator>
JAVA ACTION:
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 (Assume regular set up, getters/setters):
public NotificationMessageField(final String tag, final String description, final String dataType) {
this.tag = tag;
this.description = description;
this.dataType = dataType;
}
Upvotes: 1
Views: 2934
Reputation: 1
Add the value attribute to textfields. It will preset textfields with the initial value and once the value is preset it won't be evaluated by the name.
<s:textfield name="notMessageFieldList[%{counter}].tag" size="47" value="">
Upvotes: 1