c:非空/空检查时

时间:2013-04-04 11:16:03

标签: java jsp struts jstl

我有一个形式变量ftDtClo,其定义形式为

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

在JSP中,代码看起来像,

<c:choose>
        <c:when test="${not empty cseList.ftDtClo}">
        <c:out value="${cseList.ftDtClo}"/>
        </c:when>
        </c:choose>

但我得到了foll例外,

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)

我假设不是空的将负责空检查。我错过了什么吗?任何i / p都非常感激。

2 个答案:

答案 0 :(得分:4)

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

答案 1 :(得分:1)

尝试改变这一点:

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

如果它不起作用,请检查您的函数DtUtil.formatDate