简体   繁体   中英

Why this if statment into a Spring MVC JSP page can't work?

I am pretty new in Spring MVC and JSP page and I have the following problem.

Into a controller class I add these 2 collections to my model object:

List<Integer> numeroProgettiWifiScuoleList = new ArrayList<>();
List<Integer> numeroProgettiPnsdScuoleList = new ArrayList<>();

by these lines:

model.addAttribute("numeroProgettiWifiScuoleList", numeroProgettiWifiScuoleList);
model.addAttribute("numeroProgettiPnsdScuoleList", numeroProgettiPnsdScuoleList);

And it works fine. The problem is that now into my JSP page I have something like this:

<c:forEach items="${listaScuoleDS}" var="scuola" varStatus="item">

    <c:if test="${numeroProgettiWifiScuoleList[item.index] == 0}">
        <p>Nessun progetto WIFI associato alla scuola</p>
    </c:if>

</c:forEach>

So, as you can see, into the forEach cycle I have to perform an if test that check if the value of the numeroProgettiWifiScuoleList collection related to the current item in the iteration ( item.index ) is equal to 0. In this case show a text.

But in this way don't work (the

tag is not shown).

Why? What am I missing? How can i fix this issue?

You have to give the var name in IF condition..Because you are using JSTL tag to get the value.

<c:set var ="numeroProgettiWifiScuoleList" value=${numeroProgettiWifiScuoleList}">
    <c:forEach items="${listaScuoleDS}" var="scuola" varStatus="item">

        <c:if test="${scuola[item.index] == 0}">
            <p>Nessun progetto WIFI associato alla scuola</p>
        </c:if>

    </c:forEach>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM