Haha! OK, this was simple---my brain apparently hasn't got started yet.

I can use a WebMarkup container, and I don't have to add any HTML---I can add the wicket:id on the <li> itself:

   <ul>
      <li wicket:id="flagItem">foo</li>
      <li>bar</li>
   </ul>


Duh! The code looks like this:

   add(new WebMarkupContainer("flagItem") {
      @Override
      public boolean isVisible() {
        return flag;
      }
   });


Happy Friday!

Garret

P.S. Thanks to the Wicket SourceForge FAQ <http://wicket.sourceforge.net/faqs.html#how-hide-markup>, even though a bit old, for giving my mind a kick.


On 11/7/2014 10:32 AM, Garret Wilson wrote:
All,

I have a little list in HTML:

   <ul>
      <li>foo</li>
      <li>bar</li>
   </ul>


There are some <wicket:message> tags, but no components on the page. I want only to show the "foo" list item if the flag variable is set to true. What's the easiest way to do this in Wicket?

I've read the documentation on controlling HTML <http://wicket.apache.org/guide/guide/keepControl.html>. It seems I can use a WebMarkupContainer, but only if I add some extra HTML. Obviously I don't want this:

   <ul>
      <div wicket:id="foo"><li>foo</li></div>
      <li>bar</li>
   </ul>


It seems I can also use a Fragment (which presumably wouldn't require the extra HTML because it would use <wicket:fragment>, but the constructor for that component requires that I specify the Wicket ID of the "container", which doesn't exist.

How can I simply reference some piece of HTML so that I can show or hide it based on some flag?

Garret


Reply via email to