Question

How to put checks in a jsp page while displaying table? I want to put a check on my jsp page that if there is no data in my table it will show Result not found instead of a blank table. Below is the jsp which i am using.

<%@ taglib prefix="myFunc" uri="simpleTags"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<div id="resultContainer">
 <div id="resultChild" class="resultChild">
        <table class="TFtable" style="width: 100%;">
            <tr>
                <th colspan="2" style="font-size: 13px;">${platform} results for "${searchTerm}"</th>
            </tr>
            <tr>
                <td style="font-size: 12px;">
                    <c:forEach var="searchTerm" items="${searchTextResult}" varStatus="position">
                        <c:set var="searchTermDetail" value="${searchTerm}" />
                        <c:set var="productDetail" value="${myFunc:fetchProductDetailsTool(searchTermDetail)}" />
                        <font class="bestResult"> <a class="bestResult" title='<c:out value="${productDetail}"></c:out>'>
                        <c:out value="${searchTermDetail}"></c:out></a></font> ,                                                                                                        
                    </c:forEach>
                </td>
            </tr>
        </table>
        <br>
        <table class="TFtable" style="width: 100%;">
            <tr>
                <th colspan="2" style="font-size: 13px;">Clickstream results for "${searchTerm}" </th>
            </tr>
            <tr>
                <td style="font-size: 12px;">
                    <c:forEach var="searchTerm" items="${searchClickStreamResult}"  varStatus="position">
                        <c:set var="searchTermDetail" value="${searchTerm}" />
                        <c:set var="productDetail" value="${myFunc:fetchProductDetailsTool(searchTermDetail)}" />
                        <font class="bestResult"> <a class="bestResult" title='<c:out value="${productDetail}"></c:out>'>
                        <c:out value="${searchTermDetail}"></c:out></a></font> ,                                                                                                        
                    </c:forEach>
                </td>
            </tr>
        </table>
    </div>
</div>
Was it helpful?

Solution

if there is no data in my table it will show "Result not found" instead of a blank table

<c:choose.. does what exactly you looking for:

<c:choose>
    <c:when test="${not empty searchTextResult}">
          //table goes here
        </c:when>
    <c:otherwise>Result not found</c:otherwise>
</c:choose>

OTHER TIPS

<table class="TFtable" style="width: 100%;">
        <tr>
            <th colspan="2" style="font-size: 13px;">${platform} results for "${searchTerm}"</th>
        </tr>
        <tr>
            <td style="font-size: 12px; text-align:center;">
                <c:choose>
                <c:when test="${not empty searchTextResult}">
                <c:forEach var="searchTerm" items="${searchTextResult}" varStatus="position">
                    <c:set var="searchTermDetail" value="${searchTerm}" />
                    <c:set var="productDetail" value="${myFunc:fetchProductDetailsTool(searchTermDetail)}" />
                    <font class="bestResult"> <a class="bestResult" title='<c:out value="${productDetail}"></c:out>'>
                    <c:out value="${searchTermDetail}"></c:out></a></font> ,                                                                                                        
                </c:forEach>
                    </c:when>
            <c:otherwise>Result not found</c:otherwise>
            </c:choose>
            </td>
        </tr>
    </table>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top