All Implemented Interfaces:
Serializable, Iterable<Component>, IEventSink, IEventSource, IFeedbackContributor, IConverterLocator, IMetadataContext<Serializable,Component>, IHeaderContributor, IComponentResolver, IRequestableComponent, IHierarchical<Component>, IClusterable
Direct Known Subclasses:
InlineEnclosure

public class Enclosure extends WebMarkupContainer implements IComponentResolver
An Enclosure are automatically created by Wicket. Do not create it yourself. An Enclosure container is created if <wicket:enclosure> is found in the markup. It is meant to solve the following situation. Instead of
    <table wicket:id="label-container" class="notify"><tr><td><span wicket:id="label">[[notification]]</span></td></tr></table>
    WebMarkupContainer container=new WebMarkupContainer("label-container")
    {
       public boolean isVisible()
       {
           return hasNotification();
       }
    };
    add(container);
     container.add(new Label("label", notificationModel));
 
with Enclosure you are able to do the following:
    <wicket:enclosure>
      <table class="notify"><tr><td><span wicket:id="label">[[notification]]</span></td></tr></table>
    </wicket:enclosure>
    add(new Label("label", notificationModel))
    {
       public boolean isVisible()
       {
           return hasNotification();
       }
    }
 

Please note that since a transparent auto component is created for the tag, the markup and the component hierarchy will not be in sync which leads to subtle differences if your code relies on onBeforeRender() and validate() being called for the children inside the enclosure tag. E.g. it might happen that onBeforeRender() and validate() gets called on invisible components. In doubt, please fall back to EnclosureContainer.

Additionally due to the reason above it is not possible to assert that children in Enclosure are not visible to WicketTester.

Since:
1.3
Author:
igor, Juergen Donnerstag
See Also:
  • Constructor Details

  • Method Details

    • getChildId

      public final String getChildId()
      Returns:
      child id
    • getChild

      protected final Component getChild()
    • isVisible

      public boolean isVisible()
      Description copied from class: Component
      Gets whether this component and any children are visible.

      WARNING: this method can be called multiple times during a request. If you override this method, it is a good idea to keep it cheap in terms of processing. Alternatively, you can call Component.setVisible(boolean).

      Overrides:
      isVisible in class Component
      Returns:
      True if component and any children are visible
    • onConfigure

      protected void onConfigure()
      Description copied from class: Component
      Called on all components before any component is rendered. This method should be used to configure such things as visibility and enabled flags.

      Overrides must call super.onConfigure(), usually before any other code

      NOTE: Component hierarchy should not be modified inside this method, instead it should be done in Component.onBeforeRender()

      NOTE: Why this method is preferrable to directly overriding Component.isVisible() and Component.isEnabled()? Because those methods are called multiple times even for processing of a single request. If they contain expensive logic they can slow down the response time of the entire page. Further, overriding those methods directly on form components may lead to inconsistent or unexpected state depending on when those methods are called in the form processing workflow. It is a better practice to push changes to state rather than pull.

      NOTE: If component's visibility or another property depends on another component you may call other.configure() followed by other.isVisible() as mentioned in Component.configure() javadoc.

      NOTE: Why should Component.onBeforeRender() not be used for this? Because if a component's visibility is controlled inside Component.onBeforeRender(), once invisible the component will never become visible again.

      Overrides:
      onConfigure in class Component
    • onDetach

      protected void onDetach()
      Description copied from class: Component
      Called to allow a component to detach resources after use. Overrides of this method MUST call the super implementation, the most logical place to do this is the last line of the override method.
      Overrides:
      onDetach in class MarkupContainer
    • getEnclosureParent

      Get the real parent container
      Returns:
      enclosure's parent markup container
    • resolve

      public Component resolve(MarkupContainer container, MarkupStream markupStream, ComponentTag tag)
      Description copied from interface: IComponentResolver
      Try to resolve a component.
      Specified by:
      resolve in interface IComponentResolver
      Parameters:
      container - The container parsing its markup
      markupStream - The current markupStream
      tag - The current component tag while parsing the markup
      Returns:
      component or null if not found