如何验证jsp中列表是否为空?

时间:2016-07-06 07:15:11

标签: javascript jquery jsp

文件名:BillToparty.jsp
问题 - 如果chargelist(BilltoParty)为空,那么我们需要显示一个警报。

<c:forEach items="${chargeList}" var="charge" varStatus="count">
<td class="billToParty billingCharge${count.index}">
                            <c:if test="${not empty charge.arBillToParty}">
                                <c:choose>
                                    <c:when test="${charge.arBillToParty eq 'A'}">
                                        <c:set value="${charge.arBillToParty}" var="Agent"/>
                                        <c:set var="agentTotalAmount" value="${agentTotalAmount + charge.rolledupCharges + charge.adjustmentAmount}" />
                                        Agent
                                    </c:when>
                                    <c:when test="${charge.arBillToParty eq 'F'}">
                                        <c:set value="${charge.arBillToParty}" var="Forwarder"/>
                                        <c:set var="forwarderTotalAmount" value="${forwarderTotalAmount + charge.rolledupCharges + charge.adjustmentAmount}" />
                                        Forwarder
                                        <input type="hidden" id="fwdValidate" value="${charge.arBillToParty}">
                                    </c:when>
                                                                    </c:choose>
                            </c:if>
                        </td>
</c:forEach>
 <input type="button" class="button-style1" value="Post" id="Post" onclick="postcheck();"/>

文件名:BilltoParty.js 我在这里验证了

function postcheck() {
var flag=true;
   if ($(".billToParty").val() === "") {
              $.prompt("Please ensure all charge items have a bill to party");
              flag = false;
   }
 }

1 个答案:

答案 0 :(得分:0)

您可以检查列表是否为空,如

   <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
    <c:if test="${empty yourList}">

另一种检查尺寸的方法。但上述方法简洁易读

   <%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
   <c:if test="${fn:length(yourList) > 0}">

更新: - 看起来您想在javascript中查看

function postcheck() {
var flag=true;
   if ($("billToParty").text().trim()=="") {
              $.prompt("Please ensure all charge items have a bill to party");
              flag = false;
   }
 }