2013-09-03 1 views
0

Я использую следующий код для отображения информации, однако я получаю исключение jstl. пожалуйста, предложить какой-либо альтернативный или правильный способ справиться с этойЛучший способ использования <c:choose> в случае нескольких опций

<div class="span3"> 
     <c:choose> 
      <c:when test="${fn:length(alertStatusForm.totalSentRecipient) gt 0}"> 
       <div class="row-fluid"><div class="span12"><a href="/event/alert/recipient/list/${alertStatusForm.forAlert.id}" class="underline">${fn:length(alertStatusForm.totalSentRecipient)}</a></div></div> 
      </c:when> 
      <c:otherwise> 
         <label style="color:black"><spring:message code='alert.voice.time.others'/></label> 
      </c:otherwise> 
     </c:choose> 
     <c:choose> 
      <c:when test="${fn:length(alertStatusForm.totalNotSentRecipient) gt 0}"> 
       <div class="row-fluid"><div class="span12"><a style="color: red" href="/event/alert/recipient/list/${alertStatusForm.forAlert.id}" class="underline">${fn:length(alertStatusForm.totalNotSentRecipient)}</a></div></div> 
      </c:when> 
      <c:otherwise> 
       <label style="color:black"><spring:message code='alert.voice.time.others'/></label> 
      </c:otherwise> 
     </c:choose> 
     <c:choose> 
      <c:when test="${fn:length(alertStatusForm.totalInProgressRecipient) gt 0}"> 
       <div class="row-fluid"><div class="span12"><a href="/event/alert/recipient/list/${alertStatusForm.forAlert.id}" class="underline">${fn:length(alertStatusForm.totalInProgressRecipient)}</a></div></div> 
      </c:when> 
      <c:otherwise> 
         <label style="color:black"><spring:message code='alert.voice.time.others'/></label> 
      </c:otherwise> 
     </c:choose> 
</div> 
+0

Значит, вы хотите показывать ссылки только в том случае, когда поля 'alertStatusForm' имеют значения? Какой они? Итоги для меня предлагают целые числа. – Tap

+0

Какое у вас исключение? – Alex

ответ

1

Я не мог видеть ничего плохого в таком подходе. Тем не менее вы можете использовать код ниже, если вы не хотите смешивать код html и jstl.

<c:set var="html1" value="<div class='row-fluid'><div class='span12'><a href='/event/alert/recipient/list/${alertStatusForm.forAlert.id}' class='underline'>${fn:length(alertStatusForm.totalSentRecipient)}</a></div></div>" /> 
<c:if test="${fn:length(alertStatusForm.totalSentRecipient) lt 0}"> 
    <c:set var="html1" value="<label style='color:black'><spring:message code='alert.voice.time.others'/></label>" /> 
</c:if> 

<c:set var="html2" value="<div class='row-fluid'><div class='span12'><a style='color: red' href='/event/alert/recipient/list/${alertStatusForm.forAlert.id}' class='underline'>${fn:length(alertStatusForm.totalNotSentRecipient)}</a></div></div>" /> 
<c:if test="${fn:length(alertStatusForm.totalNotSentRecipient) lt 0}"> 
    <c:set var="html2" value="<label style='color:black'><spring:message code='alert.voice.time.others'/></label>" /> 
</c:if> 

<c:set var="html3" value="<div class='row-fluid'><div class='span12'><a href='/event/alert/recipient/list/${alertStatusForm.forAlert.id}' class='underline'>${fn:length(alertStatusForm.totalInProgressRecipient)}</a></div></div>" /> 
<c:if test="${fn:length(alertStatusForm.totalInProgressRecipient) lt 0}"> 
    <c:set var="html3" value="<label style='color:black'><spring:message code='alert.voice.time.others'/></label>" /> 
</c:if> 

<div class="span3"> 
    ${html1} 
    ${html2} 
    ${html3} 
</div>