org.apache.wicket.extensions.ajax.markup.html.modal
Class ModalWindow

java.lang.Object
  extended by org.apache.wicket.Component
      extended by org.apache.wicket.MarkupContainer
          extended by org.apache.wicket.markup.html.WebMarkupContainer
              extended by org.apache.wicket.markup.html.WebMarkupContainerWithAssociatedMarkup
                  extended by org.apache.wicket.markup.html.panel.Panel
                      extended by org.apache.wicket.extensions.ajax.markup.html.modal.ModalWindow
All Implemented Interfaces:
Serializable, IClusterable, IConverterLocator, IHeaderPartContainerProvider

public class ModalWindow
extends Panel

Modal window component.

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

In case the content is a component, it is not rendered until the window is shown (method show(AjaxRequestTarget)). In case the content is another page, you can set the desired pagemap name using setPageMapName(String). Setting pagemap is only needed when wicket multiwindow support is on.

The window can be made visible from an ajax handler using show(AjaxRequestTarget).

To close the window there are multiple options. Static method close(AjaxRequestTarget) 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 setCloseButtonCallback(ModalWindow.CloseButtonCallback). If you want to be notified when the window is closed (either using the close button or calling close(AjaxRequestTarget)), you can use setWindowClosedCallback(ModalWindow.WindowClosedCallback).

Title is specified using setTitle(String). 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).

Also it is recommended to put the modal window component in markup before any component (i.e. AjaxLink or AjaxButton) that shows it.

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.

Author:
Matej Knopp
See Also:
IPageSettings.setAutomaticMultiWindowSupport(boolean), Serialized Form

Nested Class Summary
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.
 
Nested classes/interfaces inherited from class org.apache.wicket.Component
Component.ComponentModelChange, Component.EnabledChange, Component.IVisitor<T extends Component>, Component.VisibilityChange
 
Field Summary
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.
 
Fields inherited from class org.apache.wicket.Component
ENABLE, FLAG_CONFIGURED, FLAG_INITIALIZED, FLAG_REMOVING_FROM_HIERARCHY, FLAG_RESERVED1, FLAG_RESERVED2, FLAG_RESERVED3, FLAG_RESERVED4, FLAG_RESERVED5, FLAG_RESERVED6, FLAG_RESERVED7, FLAG_RESERVED8, PATH_SEPARATOR, RENDER
 
Constructor Summary
ModalWindow(String id)
          Creates a new modal window component.
ModalWindow(String id, IModel<?> model)
          Creates a new modal window component.
 
Method Summary
 void close(AjaxRequestTarget target)
          Closes the modal window.
static void closeCurrent(AjaxRequestTarget 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).
 String getPageMapName()
          Returns the page map name.
protected  Object 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.
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 IAjaxCallDecorator
protected  void onBeforeRender()
          Called just before a component is rendered.
protected  void onComponentTag(ComponentTag tag)
          Processes the component tag.
protected  void onDetach()
          Detach the 'title' model
protected  AppendingStringBuffer postProcessSettings(AppendingStringBuffer settings)
          Method that allows tweaking the settings
 void remove(Component component)
           
 ModalWindow setCloseButtonCallback(ModalWindow.CloseButtonCallback callback)
          Sets the ModalWindow.CloseButtonCallback 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 ModalWindow.PageCreator instance.
 ModalWindow setPageMapName(String pageMapName)
          Sets the name of the page ma for the content page.
 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 ModalWindow.WindowClosedCallback instance.
 void show(AjaxRequestTarget target)
          Shows the modal window.
 
Methods inherited from class org.apache.wicket.markup.html.panel.Panel
onComponentTagBody, renderHead
 
Methods inherited from class org.apache.wicket.markup.html.WebMarkupContainerWithAssociatedMarkup
newHeaderPartContainer, renderHeadFromAssociatedMarkupFile
 
Methods inherited from class org.apache.wicket.markup.html.WebMarkupContainer
getMarkupType, getWebPage, getWebRequest
 
Methods inherited from class org.apache.wicket.MarkupContainer
add, addOrReplace, autoAdd, autoAdd, contains, findMarkupStream, get, get, getAssociatedMarkupStream, getMarkupStream, hasAssociatedMarkup, internalAdd, isTransparentResolver, iterator, iterator, newMarkupResourceStream, onAfterRenderChildren, onRender, remove, removeAll, renderAll, renderAssociatedMarkup, renderComponentTagBody, renderNext, replace, setDefaultModel, setMarkupStream, size, swap, toString, toString, visitChildren, visitChildren
 
Methods inherited from class org.apache.wicket.Component
add, addStateChange, afterRender, beforeRender, callOnBeforeRenderIfNotVisible, checkComponentTag, checkComponentTagAttribute, checkHierarchyChange, configure, continueToOriginalDestination, debug, detach, detachBehaviors, detachModel, detachModels, determineVisibility, error, exceptionMessage, fatal, findPage, findParent, findParentWithAssociatedMarkup, getApplication, getBehaviors, getBehaviors, getBehaviorsRawList, getClassRelativePath, getComponentBorder, getConverter, getConverter, getDefaultModel, getDefaultModelObject, getDefaultModelObjectAsString, getDefaultModelObjectAsString, getEscapeModelStrings, getFeedbackMessage, getFlag, getFlag, getId, getInnermostModel, getInnermostModel, getLocale, getLocalizer, getMarkupAttributes, getMarkupId, getMarkupId, getMarkupIdImpl, getMetaData, getModelComparator, getOutputMarkupId, getOutputMarkupPlaceholderTag, getPage, getPageRelativePath, getParent, getPath, getRenderBodyOnly, getRequest, getRequestCycle, getResponse, getSession, getSizeInBytes, getStatelessHint, getString, getString, getString, getStyle, getVariation, hasBeenRendered, hasErrorMessage, hasFeedbackMessage, info, initModel, internalAttach, internalDetach, internalOnAttach, internalOnDetach, internalOnModelChanged, isActionAuthorized, isAncestorOf, isAttached, isBehaviorAccepted, isEnableAllowed, isEnabled, isEnabledInHierarchy, isIgnoreAttributeModifier, isRenderAllowed, isStateless, isVersioned, isVisibilityAllowed, isVisible, isVisibleInHierarchy, locateMarkupStream, markAttached, markRendering, modelChanged, modelChanging, onAfterRender, onAttach, onBeginRequest, onConfigure, onEndRequest, onInitialize, onModelChanged, onModelChanging, onRemove, prepareForRender, prepareForRender, redirectToInterceptPage, remove, remove, render, render, renderComponent, renderComponent, renderComponentTag, rendered, renderPlaceholderTag, replaceComponentTagBody, replaceWith, sameInnermostModel, sameInnermostModel, setAuto, setComponentBorder, setDefaultModelObject, setEnabled, setEscapeModelStrings, setFlag, setFlag, setIgnoreAttributeModifier, setMarkupId, setMarkupIdImpl, setMetaData, setOutputMarkupId, setOutputMarkupPlaceholderTag, setRedirect, setRenderBodyOnly, setResponsePage, setResponsePage, setResponsePage, setVersioned, setVisibilityAllowed, setVisible, urlFor, urlFor, urlFor, urlFor, urlFor, urlFor, visitParents, warn, wrap
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

CSS_CLASS_BLUE

public static final String CSS_CLASS_BLUE
CSS class for window with blue border.

See Also:
Constant Field Values

CSS_CLASS_GRAY

public static final String CSS_CLASS_GRAY
CSS class for window with gray border.

See Also:
Constant Field Values

CONTENT_ID

public static final String CONTENT_ID
the default id of the content component

See Also:
Constant Field Values
Constructor Detail

ModalWindow

public ModalWindow(String id)
Creates a new modal window component.

Parameters:
id - Id of component

ModalWindow

public ModalWindow(String id,
                   IModel<?> model)
Creates a new modal window component.

Parameters:
id - Id of component
model - Model
Method Detail

isShown

public boolean isShown()
Is this window currently showing.

Returns:
the shown

setPageMapName

public ModalWindow setPageMapName(String pageMapName)
Sets the name of the page ma for the content page. This makes only sense when the content is a page, not a component and if wicket multiwindow support is turned on.

Parameters:
pageMapName - Name of the page map
Returns:
this

getPageMapName

public String getPageMapName()
Returns the page map name.

Returns:
The page map name.

setPageCreator

public ModalWindow setPageCreator(ModalWindow.PageCreator creator)
Sets the ModalWindow.PageCreator instance. The instance is only used when no custom component has been added to the dialog.

Parameters:
creator - ModalWindow.PageCreator instance
Returns:
this

setCloseButtonCallback

public ModalWindow setCloseButtonCallback(ModalWindow.CloseButtonCallback callback)
Sets the ModalWindow.CloseButtonCallback instance.

Parameters:
callback - Callback instance
Returns:
this

setWindowClosedCallback

public ModalWindow setWindowClosedCallback(ModalWindow.WindowClosedCallback callback)
Sets the @{link ModalWindow.WindowClosedCallback instance.

Parameters:
callback - Callback instance
Returns:
this

show

public void show(AjaxRequestTarget target)
Shows the modal window.

Parameters:
target - Request target associated with current ajax request.

closeCurrent

public static final void closeCurrent(AjaxRequestTarget target)
Hides the modal window. This can be called from within the modal window, however, the modal window must have configured WindowClosedCallback. Otherwise use the close(AjaxRequestTarget) method.

Parameters:
target - Request target associated with current ajax request.

close

public void close(AjaxRequestTarget target)
Closes the modal window.

Parameters:
target - Request target associated with current ajax request.

getShowJavascript

protected Object getShowJavascript()
Method that allows alternate script for showing the window.

Returns:
the script that actually shows the window.

getCloseJavacript

protected String getCloseJavacript()
Method that allows alternate script for closing the window.

Returns:
the script that actually closes the window.

getContentId

public String getContentId()
Returns the id of content component.
 ModalWindow window = new ModalWindow(parent, "window");
 new MyPanel(window, window.getContentId());
 

Returns:
Id of content component.

setMinimalWidth

public ModalWindow setMinimalWidth(int minimalWidth)
Sets the minimal width of window. This value is only used if the window is resizable. The width is specified in pixels and it is the width of entire window (including frame).

Parameters:
minimalWidth - Minimal window width.
Returns:
this

getMinimalWidth

public int getMinimalWidth()
Returns the minimal width of window (in pixels).

Returns:
Minimal width of window

setMinimalHeight

public ModalWindow setMinimalHeight(int minimalHeight)
Sets the minimal height of window. This value is only used if window is resizable. The height is specified in pixels and it is the height of window content (without frame).

Parameters:
minimalHeight - Minimal height
Returns:
this

getMinimalHeight

public int getMinimalHeight()
Returns the minimal height of window (in pixels).

Returns:
Minimal height of window

setCssClassName

public ModalWindow setCssClassName(String cssClassName)
Sets the CSS class name for this window. This class affects the look of window frame. Possible values (if you don't make your style sheet) are CSS_CLASS_BLUE and CSS_CLASS_GRAY.

Parameters:
cssClassName -
Returns:
this

getCssClassName

public String getCssClassName()
Returns the CSS class name for this window.

Returns:
CSS class name

setInitialWidth

public ModalWindow setInitialWidth(int initialWidth)
Sets the initial width of the window. The width refers to the width of entire window (including frame). If the window is resizable, the width unit is always "px". If the window is not resizable, the unit can be specified using setWidthUnit(String). If cookie name is set and window is resizable, the initial width may be ignored in favor of width stored in cookie.

Parameters:
initialWidth - Initial width of the window
Returns:
this

getInitialWidth

public int getInitialWidth()
Returns the initial width of the window.

Returns:
Initial height of the window

setInitialHeight

public ModalWindow setInitialHeight(int initialHeight)
Sets the initial height of the window. The height refers to the height of window content (without frame). If the window is resizable, the height unit is always "px". If the window is not resizable, the unit can be specified using setHeightUnit(String). If cookie name is set and window is resizable, the initial height may be ignored in favor of height stored in cookie.

Parameters:
initialHeight - Initial height of the window
Returns:
this

getInitialHeight

public int getInitialHeight()
Returns the initial height of the window.

Returns:
Initial height of the window

setUseInitialHeight

public ModalWindow setUseInitialHeight(boolean useInitialHeight)
Sets whether to use initial height or preserve the real content height. This can only be used if the content is a component (not a page) and the window is not resizable.

Parameters:
useInitialHeight - Whether to use initial height instead of preserving content height instead of using initial height
Returns:
this

isUseInitialHeight

public boolean isUseInitialHeight()
Returns true if the initial height should be used (in favor of preserving real content height).

Returns:
True if initial height should be used, false is real content height should be preserved (valid only if the window is not resizable and the content is a component (not a page)

setResizable

public ModalWindow setResizable(boolean resizable)
Sets whether the user will be able to resize the window.

Parameters:
resizable - Whether the window is resizable
Returns:
this

isResizable

public boolean isResizable()
Returns whether the window is resizable.

Returns:
True if the window is resizable, false otherwise

setWidthUnit

public ModalWindow setWidthUnit(String widthUnit)
Sets the CSS unit used for initial window width. This is only applicable when the window is not resizable.

Parameters:
widthUnit - CSS unit for initial window width.
Returns:
this

getWidthUnit

public String getWidthUnit()
Returns the CSS unit for initial window width.

Returns:
CSS unit for initial window width.

setHeightUnit

public ModalWindow setHeightUnit(String heightUnit)
Sets the CSS unit used for initial window height. This is only applicable when the window is not resizable.

Parameters:
heightUnit - CSS unit for initial window height.
Returns:
this

getHeightUnit

public String getHeightUnit()
Retrns the CSS unit for initial window height.

Returns:
CSS unit for initial window height.

setCookieName

public ModalWindow setCookieName(String cookieName)
Sets the name of the cookie that is used to remember window position (and size if the window is resizable).

Parameters:
cookieName - Name of the cookie
Returns:
this

getCookieName

public String getCookieName()
Returns the name of cookie that is used to remember window position (and size if the window is resizable).

Returns:
Name of the cookie

setTitle

public ModalWindow setTitle(String title)
Sets the title of window. If the window is a page, title can be null. In that case it will display the title document inside the window.

Parameters:
title - Title of the window
Returns:
this

setTitle

public ModalWindow setTitle(IModel<String> title)
Sets the title of window. If the window is a page, title can be null. In that case it will display the title document inside the window.

Parameters:
title - Title of the window
Returns:
this

getTitle

public IModel<String> getTitle()
Returns the title of the window.

Returns:
Title of the window

setMaskType

public ModalWindow setMaskType(ModalWindow.MaskType mask)
Sets the mask type of the window.

Parameters:
mask - The mask type
Returns:
this

getMaskType

public ModalWindow.MaskType getMaskType()
Returns the mask type of the window

Returns:
The mask type

onBeforeRender

protected void onBeforeRender()
Description copied from class: Component
Called just before a component is rendered.

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.

Overrides:
onBeforeRender in class Component
See Also:
Component.onBeforeRender()

makeContentVisible

protected boolean makeContentVisible()
You may subclass this method in case you don't want to show up the window on normal page refresh.

Returns:
true, if the window shall be shown

onComponentTag

protected void onComponentTag(ComponentTag tag)
Description copied from class: Component
Processes the component tag.

Overrides of this method most likely should call the super implementation.

Overrides:
onComponentTag in class Panel
Parameters:
tag - Tag to modify
See Also:
Panel.onComponentTag(org.apache.wicket.markup.ComponentTag)

getContent

protected final Component getContent()
Returns a content component. In case user haven't specified any content component, it returns an empty WebMarkupContainer.

Returns:
Content component

isCustomComponent

protected boolean isCustomComponent()
Returns true if user has added own component to the window.

Returns:
True if user has added own component to the window, false otherwise.

remove

public void remove(Component component)
Overrides:
remove in class MarkupContainer
Parameters:
component - Component to remove from this container
See Also:
MarkupContainer.remove(org.apache.wicket.Component)

setContent

public ModalWindow setContent(Component component)
Sets the content of the modal window.

Parameters:
component -
Returns:
this;

getWindowOpenJavascript

protected final String getWindowOpenJavascript()
Returns the javascript used to open the window. Subclass postProcessSettings(AppendingStringBuffer) to modify the JavaScript if needed. See WICKET-12

Returns:
javascript that opens the window

postProcessSettings

protected AppendingStringBuffer postProcessSettings(AppendingStringBuffer settings)
Method that allows tweaking the settings

Parameters:
settings -
Returns:
settings javascript

onDetach

protected void onDetach()
Detach the 'title' model

Overrides:
onDetach in class Component
See Also:
Component.onDetach()

newCloseButtonBehavior

protected ModalWindow.CloseButtonBehavior newCloseButtonBehavior()
Gives the possibility to provide custom IAjaxCallDecorator

Returns:
the behavior that should be used for the window close button


Copyright © 2004-2011 Apache Software Foundation. All Rights Reserved.