0

I'm learning Wicket and now I'm struggling with how to do a sidebar menu.

<ul class="nav nav-tabs nav-stacked">
    <li><a wicket:id="linkA">A</a></li>
    <li class="active"><a wicket:id="linkB">B</a></li>
    <li><a wicket:id="linkC">C</a></li>
    <li><a wicket:id="linkD">D</a></li>
    <li><a wicket:id="linkE">E</a></li>
</ul>

Some links won't be visible to some users (according to the role of the user) and when I'm on the page where link goes to, I want <li> to have class active (like linkB has in the example). What's the Wicket way of doing this?

Jakub Kulhan
  • 1,572
  • 2
  • 16
  • 37

2 Answers2

6

To add 'class="active"' you can simply add this to your java code:

if(...condition...){
  link.add(new AttributeAppender("class", "active");
}

To toggle visibility you can simply do this:

if(...condition...){
  item.setVisible(false);
}

where item is a WebMarkupContainer that is connected to one of the html li-tags via a wicket ID (you can also simply call link.setVisible(false), but the list bullet point would still be rendered then).

Tom
  • 3,913
  • 19
  • 28
  • Thank you for your answer. Is there a way to reference the parent node in markup, so I don't have to assign wicket:ids to all
  • s?
  • – Jakub Kulhan May 26 '13 at 11:40
  • see my comment to the next answer – Tom May 26 '13 at 17:50