I'm quite certain I'm missing something utterly insignificant, but I've not been able to figure it out.

I'm using struts 2 tags in my jsp to iterate over an object and display the results. This is conditional, there's a check to see if the object is not null before it can iterate. The if part works perfectly, it prints out the list of movies. But the else does not seem to work.

    <s:if test="%{listmovies != null}">
        <s:iterator value="listmovies">
            <s:property value="title" />
            <br>
        </s:iterator>
    </s:if>
    <s:else>No movies!</s:else>
有帮助吗?

解决方案

Recheck that your listmovies is not an empty collection and invert your condition to simplify it:

<s:if test="%{listmovies.isEmpty()}">No movies!</s:if>
<s:else>
    <s:iterator value="listmovies">
        <s:property value="title" />
        <br>
    </s:iterator>
</s:else>
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top