Search code examples
javahtmlwicketwicket-6

Removing an HTML tag using Wicket


I am using wicket to develop a web application. Let's say I have the following HTML:

<div wicket:id="myDiv">
    ...content...
</div>

Now, that div is there because most of the time I want to write content inside it. But what if there are cases where I want to delete that div (and its content) entirely? Is this possible in wicket?

I tried:

remove("myDiv");

in my Java backend, but it throws an exception:

Unexpected RuntimeException
Last cause: Unable to find a component with id 'myDiv' to remove

Any hints? I'm new to wicket and I find that it's incredibly difficult to find documentation on how to do even trivial things like this one...


Solution

  • The simplest solution is adding an invisible WebMarkupContainer, then it won't render in the resulting HTML code:

    add(WebMarkupContainer("myDiv").setVisible(false));