Domanda

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>
È stato utile?

Soluzione

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>
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top