Search code examples
javahtmlwicketwicket-6

Wicket RepeatingView: delete placeholder if list is empty


I'm using the wicket RepeatingView to implement a list of items. The HTML is as follows:

<ul>
    <li wicket:id="listItemFoo">
        ...content...
    </li>
</ul>

And on the java backend I do:

RepeatingView listFoo = new RepeatingView("listItemFoo");
//put items inside listFoo
addOrReplace(listFoo);

This works corretly, but it has one problem. There are cases in my application where there are NO items to add to the list. In that case I'd like the repeater to output nothing. However, this isn't the case: if the repeater in empty it will still output a single, empty <li></li>. This is annoying because it displays an empty bullet point in the page. What is the correct way to avoid this? (I know it might be trivial, but I'm very new to wicket as you can probably tell)


Solution

  • I solved the problem like this:

    <ul>
        <wicket:container wicket:id="listItemFoo">
            <li>
                ...content...
            </li>
        </wicket:container>                         
    </ul>
    

    This way, when the list is empty the container won't even be generated.