Class Enclosure
- java.lang.Object
-
- org.apache.wicket.Component
-
- org.apache.wicket.MarkupContainer
-
- org.apache.wicket.markup.html.WebMarkupContainer
-
- org.apache.wicket.markup.html.internal.Enclosure
-
- 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:
EnclosureHandler
,EnclosureContainer
, Serialized Form
-
-
Field Summary
-
Fields inherited from class org.apache.wicket.Component
ENABLE, FLAG_INITIALIZED, FLAG_RESERVED1, FLAG_RESERVED2, FLAG_RESERVED3, FLAG_RESERVED4, FLAG_RESERVED5, FLAG_RESERVED8, PARENT_PATH, PATH_SEPARATOR, RENDER, RFLAG_CONTAINER_DEQUEING, RFLAG_CONTAINER_HAS_REMOVALS
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected Component
getChild()
String
getChildId()
protected MarkupContainer
getEnclosureParent()
Get the real parent containerboolean
isVisible()
Gets whether this component and any children are visible.protected void
onConfigure()
Called on all components before any component is rendered.protected void
onDetach()
Called to allow a component to detach resources after use.Component
resolve(MarkupContainer container, MarkupStream markupStream, ComponentTag tag)
Try to resolve a component.-
Methods inherited from class org.apache.wicket.markup.html.WebMarkupContainer
getWebApplication, getWebPage, getWebRequest, getWebResponse, getWebSession
-
Methods inherited from class org.apache.wicket.MarkupContainer
add, addDequeuedComponent, addOrReplace, autoAdd, canDequeueTag, contains, dequeue, dequeue, dequeuePreamble, findChildComponent, findComponentToDequeue, get, getAssociatedMarkup, getAssociatedMarkupStream, getMarkup, getMarkupType, getRegionMarkup, internalAdd, internalInitialize, iterator, iterator, newDequeueContext, onComponentTagBody, onInitialize, onRender, queue, remove, remove, removeAll, renderAll, renderAssociatedMarkup, renderAssociatedMarkup, renderNext, replace, setDefaultModel, size, stream, streamChildren, toString, toString, visitChildren, visitChildren
-
Methods inherited from class org.apache.wicket.Component
add, addStateChange, beforeRender, canCallListener, canCallListenerAfterExpiry, checkComponentTag, checkComponentTagAttribute, checkHierarchyChange, clearOriginalDestination, configure, continueToOriginalDestination, createConverter, debug, detach, detachModel, detachModels, determineVisibility, error, exceptionMessage, fatal, findMarkupStream, findPage, findParent, findParentWithAssociatedMarkup, getAjaxRegionMarkupId, getApplication, getBehaviorById, getBehaviorId, getBehaviors, getBehaviors, getClassRelativePath, getConverter, getDefaultModel, getDefaultModelObject, getDefaultModelObjectAsString, getDefaultModelObjectAsString, getEscapeModelStrings, getFeedbackMessages, getFlag, getId, getInnermostModel, getInnermostModel, getLocale, getLocalizer, getMarkup, getMarkupAttributes, getMarkupId, getMarkupId, getMarkupIdFromMarkup, getMarkupIdImpl, getMarkupSourcingStrategy, getMarkupTag, getMetaData, getModelComparator, getOutputMarkupId, getOutputMarkupPlaceholderTag, getPage, getPageRelativePath, getParent, getPath, getRenderBodyOnly, getRequest, getRequestCycle, getRequestFlag, getResponse, getSession, getSizeInBytes, getStatelessHint, getString, getString, getString, getStyle, getVariation, hasBeenRendered, hasErrorMessage, hasFeedbackMessage, info, initModel, internalOnModelChanged, internalRenderComponent, internalRenderHead, isActionAuthorized, isAuto, isBehaviorAccepted, isEnableAllowed, isEnabled, isEnabledInHierarchy, isIgnoreAttributeModifier, isInitialized, isRenderAllowed, isRendering, isStateless, isVersioned, isVisibilityAllowed, isVisibleInHierarchy, markRendering, modelChanged, modelChanging, newMarkupSourcingStrategy, onAfterRender, onBeforeRender, onComponentTag, onEvent, onModelChanged, onModelChanging, onReAdd, onRemove, redirectToInterceptPage, remove, remove, render, renderComponentTag, rendered, renderHead, renderPart, renderPlaceholderTag, replaceComponentTagBody, replaceWith, sameInnermostModel, sameInnermostModel, send, setAuto, setDefaultModelObject, setEnabled, setEscapeModelStrings, setFlag, setIgnoreAttributeModifier, setMarkup, setMarkupId, setMarkupIdImpl, setMetaData, setOutputMarkupId, setOutputMarkupPlaceholderTag, setParent, setRenderBodyOnly, setResponsePage, setResponsePage, setResponsePage, setVersioned, setVisibilityAllowed, setVisible, success, urlFor, urlFor, urlFor, urlForListener, urlForListener, visitParents, visitParents, warn, wrap
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
-
-
-
Method Detail
-
getChildId
public final String getChildId()
- Returns:
- child id
-
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)
.
-
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 codeNOTE: 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()
andComponent.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 byother.isVisible()
as mentioned inComponent.configure()
javadoc.NOTE: Why should
Component.onBeforeRender()
not be used for this? Because if a component's visibility is controlled insideComponent.onBeforeRender()
, once invisible the component will never become visible again.- Overrides:
onConfigure
in classComponent
-
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 classMarkupContainer
-
getEnclosureParent
protected 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 interfaceIComponentResolver
- Parameters:
container
- The container parsing its markupmarkupStream
- The current markupStreamtag
- The current component tag while parsing the markup- Returns:
- component or
null
if not found
-
-