Wicket ListView: do not output "container" tag

409 views Asked by At

I'm trying to create a ListView or a Repeater in Wicket 6 in order to output a list of items like this:

<div class="header">My first header</div>
<div class="content">My first content</div>

<div class="header">My second header</div>
<div class="content">My second content</div>

<div class="header">My third header</div>
<div class="content">My third content</div>

...

I tried to use a ListView like this:

<div wicket:id="listViewItems">
    <div class="header" wicket:id="header"></div>
    <div class="content" wicket:id="content"></div>
</div>

and populate it like this:

add(new ListView<MyItem>("listViewItems", myListOfItems) {
        @Override
        protected void populateItem(ListItem<MyItem> item) {
            item.add(new Label("header", new PropertyModel(item.getModel(), "header")));
            item.add(new Label("content", new PropertyModel(item.getModel(), "content")));
        }           
   });

The output I get is:

<div>
    <div class="header">My first header</div>
    <div class="content">My first content</div>
</div>

<div>
    <div class="header">My second header</div>
    <div class="content">My second content</div>
</div>

<div>
    <div class="header">My third header</div>
    <div class="content">My third content</div>
</div>

The problem is this: I don't want those outer divs that wrap every header/content couple. I want the list to be "flat" like in the example I made above.

How can I achieve this?

1

There are 1 answers

1
soorapadman On BEST ANSWER

You can give setRenderBodyOnly(true) for ListView or use wicket:container in HTML instead of div

like below

<wicket:container wicket:id="listViewItems">
    <div class="header" wicket:id="header"></div>
    <div class="content" wicket:id="content"></div>
</wicket:container>