c:when not null/empty check
49,133
Solution 1
<c:choose>
<c:if test=${cseList != null}>
<c:when test="${not empty cseList.ftDtClo}">
<c:out value="${cseList.ftDtClo}"/>
</c:when>
</c:if>
</c:choose>
Solution 2
Try to change this:
public String getFtDtClo () {
String dateStr = "";
if(this.getCse()!=null && this.getCse().getDtClo()!=null) {
dStr = DtUtil.formatDate(this.getCse().getDtClo(), DtUtil.FORMAT_MM_DD_YYYY_KK_MM_SS);
}
return dateStr;
}
If it does not work, check your function DtUtil.formatDate
as well.
Author by
Geek
Updated on July 09, 2022Comments
-
Geek almost 2 years
I have a forma variable ftDtClo defined in form like,
public String getFtDtClo () { String dateStr = ""; if(this.getCse().getDtClo()!=null) { dStr = DtUtil.formatDate(this.getCse().getgetDtClo(), DtUtil.FORMAT_MM_DD_YYYY_KK_MM_SS); } return dateStr; }
In JSP the code looks like,
<c:choose> <c:when test="${not empty cseList.ftDtClo}"> <c:out value="${cseList.ftDtClo}"/> </c:when> </c:choose>
But i get the foll exception,
wrapped exception: javax.servlet.jsp.JspException: javax.servlet.jsp.JspException: An error occurred while evaluating custom action attribute "test" with value "${not empty cseList.ftDtClo}": An error occurred while getting property "ftDtClo" from an instance of class abc.cseDetailLists (java.lang.NullPointerException) at org.apache.taglibs.standard.tag.common.core.ImportSupport.acquireString(ImportSupport.java:306) at org.apache.taglibs.standard.tag.common.core.ImportSupport.doEndTag(ImportSupport.java:161)
Im assuming not empty will take care of null check. Am i missing something? any i/p is highly appreciated.
-
Geek about 11 yearsNO cseList is not null...getFtDtClo() is null..however im doing the null check using not EMPTY. And the rest of the fields are good. So im assuming its only the ftDtClo being null.
-
Geek about 11 yearsthis.getCse() is not null. It has around 10 field which displays values except this field.