public class ModalWindow extends Panel
Modal window is a draggable window (with either div or iframe content) that prevent user from interacting the rest of page (using a mask) until the window is closed.
If you want this to work under IE, don't attach this component to a <span> tag, make sure you use a <div>.
The window is draggable and optionally resizable. The content can be either
getContentId()
, or
ModalWindow.PageCreator
instance to a
setPageCreator(ModalWindow.PageCreator)
method.
show(IPartialPageRequestHandler)
)
. The window can be made
visible from an ajax handler using
show(IPartialPageRequestHandler)
.
To close the window there are multiple options. Static method
can be used to close the
window from a handler of ajax link inside the window. By default the close button in the upper
right corner of the window closes it. This behavior can be altered using
close(IPartialPageRequestHandler)
. If you want to be
notified when the window is closed (either using the close button or calling
setCloseButtonCallback(ModalWindow.CloseButtonCallback)
, you can use
close(IPartialPageRequestHandler)
)
.
setWindowClosedCallback(ModalWindow.WindowClosedCallback)
Title is specified using setTitle(String)
. Pass true
to
to use unencoded markup in the title.
Component.setEscapeModelStrings(boolean)
If the content is a page (iframe), the title can remain unset, in that case title from the page
inside window will be shown.
There are several options to specify the visual properties of the window. In all methods where size is expected, width refers to width of entire window (including frame), height refers to the height of window content (without frame).
setResizable(boolean)
specifies, whether the window can be resized.
setInitialWidth(int)
and setInitialHeight(int)
specify the initial width and height of window. If the window is resizable, the unit of these
dimensions is always "px". If the window is not resizable, the unit can be specified using
setWidthUnit(String)
and setHeightUnit(String)
. If
the window is not resizable and the content is a component (not a page), the initial height value
can be ignored and the actual height can be determined from the height of the content. To enable
this behavior use setUseInitialHeight(boolean)
.
setCookieName(String)
. If the name is null
, position is not
stored (initial width and height are always used). Default cookie name is null (position is not
stored).
setMinimalWidth(int)
and setMinimalHeight(int)
set the minimal dimensions of resizable window.
setAutoSize(boolean)
sets whether window size will be automatically
adjusted on opening to fit content's width and height. Default is false. Doesn't work on IE 6.setCssClassName(String)
sets the dialog css class, possible values are
CSS_CLASS_BLUE
for blue frame and CSS_CLASS_GRAY
for
gray frame.
setMaskType(ModalWindow.MaskType)
alters
this.
If you want to use form in modal window component make sure that you put the modal window itself in another form (nesting forms is legal in Wicket) and that the form on modal window is submitted before the window get closed.
Modifier and Type | Class and Description |
---|---|
protected class |
ModalWindow.CloseButtonBehavior |
static interface |
ModalWindow.CloseButtonCallback
Callback for close button that contains a method that is invoked after the button has been
clicked.
|
static class |
ModalWindow.MaskType
Mask is the element behind the window, that prevents user from interacting the rest of page.
|
static interface |
ModalWindow.PageCreator
Interface for lazy page creation.
|
static interface |
ModalWindow.WindowClosedCallback
Callback called after the window has been closed.
|
Modifier and Type | Field and Description |
---|---|
static String |
CONTENT_ID
the default id of the content component
|
static String |
CSS_CLASS_BLUE
CSS class for window with blue border.
|
static String |
CSS_CLASS_GRAY
CSS class for window with gray border.
|
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
Constructor and Description |
---|
ModalWindow(String id)
Creates a new modal window component.
|
ModalWindow(String id,
IModel<?> model)
Creates a new modal window component.
|
Modifier and Type | Method and Description |
---|---|
void |
close(IPartialPageRequestHandler target)
Closes the modal window.
|
static void |
closeCurrent(IPartialPageRequestHandler target)
Hides the modal window.
|
protected String |
getCloseJavacript()
Method that allows alternate script for closing the window.
|
protected Component |
getContent()
Returns a content component.
|
String |
getContentId()
Returns the id of content component.
|
String |
getCookieName()
Returns the name of cookie that is used to remember window position (and size if the window
is resizable).
|
String |
getCssClassName()
Returns the CSS class name for this window.
|
String |
getHeightUnit()
Retrns the CSS unit for initial window height.
|
int |
getInitialHeight()
Returns the initial height of the window.
|
int |
getInitialWidth()
Returns the initial width of the window.
|
ModalWindow.MaskType |
getMaskType()
Returns the mask type of the window
|
int |
getMinimalHeight()
Returns the minimal height of window (in pixels).
|
int |
getMinimalWidth()
Returns the minimal width of window (in pixels).
|
protected CharSequence |
getShowJavaScript()
Method that allows alternate script for showing the window.
|
IModel<String> |
getTitle()
Returns the title of the window.
|
String |
getWidthUnit()
Returns the CSS unit for initial window width.
|
protected String |
getWindowOpenJavaScript()
Returns the javascript used to open the window.
|
boolean |
isAutoSize()
Returns whether window will be opened in autosize mode.
|
protected boolean |
isCustomComponent()
Returns true if user has added own component to the window.
|
boolean |
isResizable()
Returns whether the window is resizable.
|
boolean |
isShown()
Is this window currently showing.
|
boolean |
isUseInitialHeight()
Returns true if the initial height should be used (in favor of preserving real content
height).
|
protected boolean |
makeContentVisible()
You may subclass this method in case you don't want to show up the window on normal page
refresh.
|
protected ModalWindow.CloseButtonBehavior |
newCloseButtonBehavior()
Gives the possibility to provide custom
IAjaxCallListener |
protected ResourceReference |
newCssResource()
Allows to override CSS contribution.
|
protected void |
onBeforeRender()
Called on all visible components before any component is rendered.
|
protected void |
onComponentTag(ComponentTag tag)
Processes the component tag.
|
protected void |
onDetach()
Detach the 'title' model
|
protected void |
postProcessSettings(com.github.openjson.JSONObject settings)
Method that allows tweaking the settings
|
ModalWindow |
remove(Component component)
Removes a component from the children identified by the
component.getId() |
void |
renderHead(IHeaderResponse response)
Render to the web response whatever the component wants to contribute to the head section.
|
ModalWindow |
setAutoSize(boolean autoSize)
Sets whether window size will be automatically adjusted on opening to fit content's width and
height.
|
ModalWindow |
setCloseButtonCallback(ModalWindow.CloseButtonCallback callback)
Sets the
instance. |
ModalWindow |
setContent(Component component)
Sets the content of the modal window.
|
ModalWindow |
setCookieName(String cookieName)
Sets the name of the cookie that is used to remember window position (and size if the window
is resizable).
|
ModalWindow |
setCssClassName(String cssClassName)
Sets the CSS class name for this window.
|
ModalWindow |
setHeightUnit(String heightUnit)
Sets the CSS unit used for initial window height.
|
ModalWindow |
setInitialHeight(int initialHeight)
Sets the initial height of the window.
|
ModalWindow |
setInitialWidth(int initialWidth)
Sets the initial width of the window.
|
ModalWindow |
setMaskType(ModalWindow.MaskType mask)
Sets the mask type of the window.
|
ModalWindow |
setMinimalHeight(int minimalHeight)
Sets the minimal height of window.
|
ModalWindow |
setMinimalWidth(int minimalWidth)
Sets the minimal width of window.
|
ModalWindow |
setPageCreator(ModalWindow.PageCreator creator)
Sets the
instance. |
ModalWindow |
setResizable(boolean resizable)
Sets whether the user will be able to resize the window.
|
ModalWindow |
setTitle(IModel<String> title)
Sets the title of window.
|
ModalWindow |
setTitle(String title)
Sets the title of window.
|
ModalWindow |
setUseInitialHeight(boolean useInitialHeight)
Sets whether to use initial height or preserve the real content height.
|
ModalWindow |
setWidthUnit(String widthUnit)
Sets the CSS unit used for initial window width.
|
ModalWindow |
setWindowClosedCallback(ModalWindow.WindowClosedCallback callback)
Sets the
@{link instance. |
void |
show(IPartialPageRequestHandler target)
Shows the modal window.
|
boolean |
showUnloadConfirmation()
Returns whether the user should be asked before leaving the page.
|
ModalWindow |
showUnloadConfirmation(boolean unloadConfirmation)
Sets a flag whether to ask the user before leaving the page.
|
getRegionMarkup, newMarkupSourcingStrategy
getWebApplication, getWebPage, getWebRequest, getWebResponse, getWebSession
add, addDequeuedComponent, addOrReplace, autoAdd, canDequeueTag, contains, dequeue, dequeue, dequeuePreamble, findChildComponent, findComponentToDequeue, get, getAssociatedMarkup, getAssociatedMarkupStream, getMarkup, getMarkupType, internalAdd, internalInitialize, iterator, iterator, newDequeueContext, onComponentTagBody, onInitialize, onRender, queue, remove, removeAll, renderAll, renderAssociatedMarkup, renderNext, replace, setDefaultModel, size, stream, streamChildren, toString, toString, visitChildren, visitChildren
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, 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, isVisible, isVisibleInHierarchy, markRendering, modelChanged, modelChanging, onAfterRender, onConfigure, onEvent, onModelChanged, onModelChanging, onReAdd, onRemove, redirectToInterceptPage, remove, remove, render, renderComponentTag, rendered, 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
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
dequeue, newDequeueContext
forEach, spliterator
public static final String CSS_CLASS_BLUE
public static final String CSS_CLASS_GRAY
public static final String CONTENT_ID
public ModalWindow(String id)
id
- Id of componentpublic void renderHead(IHeaderResponse response)
Component
renderHead
in interface IHeaderContributor
renderHead
in class Component
response
- Response objectprotected ResourceReference newCssResource()
setCssClassName(String)
public boolean isShown()
public ModalWindow setPageCreator(ModalWindow.PageCreator creator)
ModalWindow.PageCreator
instance. The instance is only used when no custom
component has been added to the dialog.creator
- ModalWindow.PageCreator
instancepublic ModalWindow setCloseButtonCallback(ModalWindow.CloseButtonCallback callback)
ModalWindow.CloseButtonCallback
instance.callback
- Callback instancepublic ModalWindow setWindowClosedCallback(ModalWindow.WindowClosedCallback callback)
@{link ModalWindow.WindowClosedCallback
instance.callback
- Callback instancepublic void show(IPartialPageRequestHandler target)
target
- Request target associated with current ajax request.public static void closeCurrent(IPartialPageRequestHandler target)
close(IPartialPageRequestHandler)
method.target
- Request target associated with current ajax request.public void close(IPartialPageRequestHandler target)
target
- Request target associated with current ajax request.protected CharSequence getShowJavaScript()
protected String getCloseJavacript()
public String getContentId()
ModalWindow window = new ModalWindow(parent, "window"); new MyPanel(window, window.getContentId());
public ModalWindow setMinimalWidth(int minimalWidth)
minimalWidth
- Minimal window width.public int getMinimalWidth()
public ModalWindow setMinimalHeight(int minimalHeight)
minimalHeight
- Minimal heightpublic int getMinimalHeight()
public ModalWindow setCssClassName(String cssClassName)
CSS_CLASS_BLUE
and CSS_CLASS_GRAY
.cssClassName
- newCssResource()
public String getCssClassName()
public ModalWindow setInitialWidth(int initialWidth)
setWidthUnit(String)
. If cookie
name is set and window is resizable, the initial width may be ignored in favor of width
stored in cookie.initialWidth
- Initial width of the windowpublic int getInitialWidth()
public ModalWindow setInitialHeight(int initialHeight)
setHeightUnit(String)
. If cookie name
is set and window is resizable, the initial height may be ignored in favor of height stored
in cookie.initialHeight
- Initial height of the windowpublic int getInitialHeight()
public ModalWindow setUseInitialHeight(boolean useInitialHeight)
useInitialHeight
- Whether to use initial height instead of preserving content height instead of
using initial heightpublic boolean isUseInitialHeight()
public ModalWindow setResizable(boolean resizable)
resizable
- Whether the window is resizablepublic boolean isResizable()
public ModalWindow showUnloadConfirmation(boolean unloadConfirmation)
unloadConfirmation
- a flag whether to ask the user before leaving the pagethis
instance, for chainingpublic boolean showUnloadConfirmation()
true
if the user should be asked if the last action causes leaving the page,
false
otherwisepublic ModalWindow setWidthUnit(String widthUnit)
widthUnit
- CSS unit for initial window width.public String getWidthUnit()
public ModalWindow setHeightUnit(String heightUnit)
heightUnit
- CSS unit for initial window height.public String getHeightUnit()
public ModalWindow setCookieName(String cookieName)
cookieName
- Name of the cookiepublic String getCookieName()
public ModalWindow setTitle(String title)
null
. In that
case it will display the title document inside the window.title
- Title of the windowpublic ModalWindow setTitle(IModel<String> title)
null
. In that
case it will display the title document inside the window.title
- Title of the windowpublic IModel<String> getTitle()
public ModalWindow setMaskType(ModalWindow.MaskType mask)
mask
- The mask typepublic ModalWindow.MaskType getMaskType()
protected void onBeforeRender()
Component
NOTE: If you override this, you *must* call super.onBeforeRender() within
your implementation.
Because this method is responsible for cascading Component.onBeforeRender()
call to its
children it is strongly recommended that super call is made at the end of the override.
onBeforeRender
in class Component
Component.onBeforeRender()
protected boolean makeContentVisible()
protected void onComponentTag(ComponentTag tag)
Component
onComponentTag
in class Component
tag
- Tag to modifyComponent.onComponentTag(org.apache.wicket.markup.ComponentTag)
protected final Component getContent()
protected boolean isCustomComponent()
public ModalWindow remove(Component component)
MarkupContainer
component.getId()
remove
in class MarkupContainer
component
- Component to remove from this containerthis
for chainingMarkupContainer.remove(org.apache.wicket.Component)
public ModalWindow setContent(Component component)
component
- protected final String getWindowOpenJavaScript()
#postProcessSettings(AppendingStringBuffer)
to modify the JavaScript if needed.
See WICKET-12protected void postProcessSettings(com.github.openjson.JSONObject settings)
settings
- protected void onDetach()
onDetach
in class MarkupContainer
Component.onDetach()
public ModalWindow setAutoSize(boolean autoSize)
autoSize
- Whether window size will be automatically adjustedpublic boolean isAutoSize()
protected ModalWindow.CloseButtonBehavior newCloseButtonBehavior()
IAjaxCallListener
Copyright © 2006–2022 Apache Software Foundation. All rights reserved.