spring 多对一表在jsp页面判断为空时报错。

wenwen1 发布于 2012/12/24 14:03
阅读 431
收藏 0

activity表中task_ID和task表的关系为 CONSTRAINT `FK_activity_task` FOREIGN KEY (`Task_ID`) REFERENCES `task` (`ID`)。

在domian中的代码为:

Task.java

/**
  */
 @OneToMany(mappedBy = "task", cascade = { CascadeType.REMOVE }, fetch = FetchType.LAZY)
 @XmlElement(name = "", namespace = "")
 java.util.Set<net.gvsun.domain.Activity> activities;

Activity.java

/**
  */
 @ManyToOne(fetch = FetchType.LAZY)
 @JoinColumns({ @JoinColumn(name = "Task_ID", referencedColumnName = "ID") })
 @XmlTransient
 Task task;

我在jsp里面是这么写的:

<table cellpadding="0" cellspacing="0" id="viewTable" class="tablesorter">
    <thead>
     <tr>
     <th  width="15%"><fmt:message key="task.responser.title"/></th>
     <th  width="20%"><fmt:message key="task.specification.title"/></th>
     <th  width="10%"><fmt:message key="task.planbegindate.title"/></th>
     <th  width="10%"><fmt:message key="task.planenddate.title"/></th>
     <th  width="25%"><fmt:message key="task.projectactivity.title"/></th>
     <th  width="10%"><fmt:message key="task.createddate.title"/></th>
     <th  width="10%"><fmt:message key="task.creater.title"/></th>
     <th  width="8%"><fmt:message key="operation"/></th>
     </tr>
    </thead>
    <tbody>
     <c:forEach items="${tasks}" var="current"  varStatus="i"> 
      <c:choose>
       <c:when test="${(i.count) % 2 == 0}">
           <c:set var="rowclass" value="rowtwo"/>
       </c:when><c:otherwise>
           <c:set var="rowclass" value="rowone"/>
       </c:otherwise></c:choose>
     <tr class="${rowclass}">
      <td>${current.userByResponser.cname}&nbsp;</td>
      <td>${current.specification}&nbsp;</td>
      <td>
        <fmt:formatDate type="date" dateStyle="medium" value="${current.planBeginDate.time}"/>&nbsp;
      </td><td>
        <fmt:formatDate dateStyle="medium" type="date" value="${current.planEndDate.time}"/>&nbsp;
      </td><td>
      <c:choose>
      <c:when test="${current.activities==null}">
      <a class="button" href="${pageContext.request.contextPath}/addProjectActivity?idKey=${project.id}&"><span><img src="${pageContext.request.contextPath}/images/icons/new.gif" /><fmt:message key="activity.title"/></span></a>
      </c:when><c:otherwise>
      <table cellpadding="0" cellspacing="0" id="viewTable" class="tablesorter">            
             <thead><th></th><th></th><th></th></thead>
              <tbody>
           <c:forEach items="${current.activities}" var="activities"  varStatus="j"> 
        <c:choose><c:when test="${(j.count) % 2 == 0}">
          <c:set var="rowclass" value="rowtwo"/></c:when>
       <c:otherwise><c:set var="rowclass" value="rowone"/>
       </c:otherwise></c:choose>
          <tr class="${rowclass}">
           <td>${activities.activityField}&nbsp;:&nbsp;</td>
           <td>${activities.userByCreater.cname}&nbsp;:&nbsp;</td>
           <td style="color:red;">
           <fmt:formatDate dateStyle="medium" type="date" value="${activities.activityTime.time}"/>&nbsp;
                             </td></tr>
              </c:forEach></tbody>
              </table>
               </c:otherwise>
              </c:choose>
      </td><td>
        <fmt:formatDate pattern="yyyy-MM-dd,HH:mm" type="both" value="${current.createdDate.time}"/>&nbsp;
      </td><td>
      ${current.userByCreater.cname}&nbsp;
      </td><td  nowrap="nowrap" class="tabletd">
           <a title="<fmt:message key="navigation.edit" />" href="${pageContext.request.contextPath}/updateProjectPlan?idKey=${current.id}&"><img src="${pageContext.request.contextPath}/images/icons/edit.gif" /></a>        
        <a title="<fmt:message key="navigation.delete" />" href="${pageContext.request.contextPath}/deleteOldProjectPlan?id=${current.id}&" onclick='return confirm("<fmt:message key="confirm.if.delete"/>")'><img src="${pageContext.request.contextPath}/images/icons/delete.gif" /></a>
         &nbsp;
         </td>
     </tr>
     </c:forEach>
    </tbody>
   </table>

为什么我的数据库中activity表中的task_ID为NULL,而我在jsp里面写${current.activities==null}"时,出现新增按钮,否则就显示一个表格,但是为什么总是显示了一个表格啊?难道这样默认current.activities不为空。
     

 

 

以下是问题补充:

@wenwen1:${current.activities}在页面上显示成[]<c:when test=${current.activities==}该怎么写呢? (2012/12/24 14:20)
加载中
0
zjxzjx
zjxzjx

<c:if test="${current.activities==null}"> </c:if>


0
zjxzjx
zjxzjx
先输出到页面看看值是什么吧 <c:out value="${ current.activities}">
0
wad12302
wad12302

isempty jstl 有  isempty 判断

${empty xxxxx} or ${ !empty xxxxx} or ${ not empty xxxxx}


wenwen1
wenwen1
谢谢啊!
OSCHINA
登录后可查看更多优质内容
返回顶部
顶部