3

次のような形式で定義されたフォーマ変数 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>

しかし、私は次の例外を受け取ります、

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)

空でない場合はnullチェックが行われると想定しています。何か不足していますか?任意の i/p を高く評価します。

4

2 に答える 2

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も確認してください。

于 2013-04-04T23:28:49.080 に答える