Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Adding section to describe the best practices for implementing component visibility changes per the user mailing list

...

Panel
Wiki Markup
 Wicket:
   code:
   
   WebMarkupContainer blahRow = new WebMarkupContainer ("blahrow") {
     public boolean isVisible() {
       return blah;
     }
   }
   blahRow.add(new TextField("comp",...));
 
   template:
   <span wicket:id="blahrow">
     Answer me: <input type="text" wicket:id="comp"/>
   &lt;/span>

Clarification on defining component visibility

Based on the user mailing list, here are some things to keep in mind when dealing with conditional visibility.

If the component itself controls its own visibility the best way is to override onConfigure() and call setVisible() inside.

If an outside component controls another’s visibility the best way is to override the controlling component’s onConfigure() and call controlled.setVisible()

If you have a simple state toggle, like “when i click this link i want this component’s visibility to change” then calling component.setVisible() is fine.

If you have a cross-cutting concern (authorization strategy, configure listener, before render listener, etc) overriding component’s visibility then call component.setVisibilityAllowed(). Wicket ands this bit with the visible bit to determine final visibility; this way the cross-cutting concern won’t dirty component’s visibility attribute.

Note
titleIf all of these fail...

If all of these fail, as a last resort override component.isVisible() but be warned that this has a few pitfalls:

  • it is called multiple times per request, potentially tens of times, so keep the implementation computationally light
  • this value should remain stable across the render/respond boundary. Meaning if isVisible() returns true when rendering a button, but when the button is clicked returns false you will get an error

The Panel Method

  • Create two panels that display either state that you will possibly want shown, and swap them as needed.

...