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:
java.io.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).

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

Nested Class Summary
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, Component.VisibilityChange
 
Field Summary
static java.lang.String CSS_CLASS_BLUE
          CSS class for window with blue border.
static java.lang.String CSS_CLASS_GRAY
          CSS class for window with gray border.
 
Fields inherited from class org.apache.wicket.Component
ENABLE, FLAG_RESERVED1, FLAG_RESERVED2, FLAG_RESERVED3, FLAG_RESERVED4, FLAG_RESERVED5, FLAG_RESERVED6, FLAG_RESERVED7, FLAG_RESERVED8, PATH_SEPARATOR, RENDER
 
Constructor Summary
ModalWindow(java.lang.String id)
          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.
 java.lang.String getContentId()
          Returns the id of content component.
 java.lang.String getCookieName()
          Returns the name of cookie that is used to remember window position (and size if the window is resizable).
 java.lang.String getCssClassName()
          Returns the CSS class name for this window.
 java.lang.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).
 java.lang.String getPageMapName()
          Returns the page map name.
 IModel getTitle()
          Returns the title of the window.
 java.lang.String getWidthUnit()
          Returns the CSS unit for initial window width.
 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  void onBeforeRender()
          Called just before a component is rendered.
protected  void onComponentTag(ComponentTag tag)
          Processes the component tag.
protected  void onDetach()
          Called to allow a component to detach resources after use.
protected  AppendingStringBuffer postProcessSettings(AppendingStringBuffer settings)
          Method that allows tweaking the settings
 void remove(Component component)
           
 void setCloseButtonCallback(ModalWindow.CloseButtonCallback callback)
          Sets the ModalWindow.CloseButtonCallback instance.
 void setContent(Component component)
          Sets the content of the modal window.
 void setCookieName(java.lang.String cookieName)
          Sets the name of the cookie that is used to remember window position (and size if the window is resizable).
 void setCssClassName(java.lang.String cssClassName)
          Sets the CSS class name for this window.
 void setHeightUnit(java.lang.String heightUnit)
          Sets the CSS unit used for initial window height.
 void setInitialHeight(int initialHeight)
          Sets the initial height of the window.
 void setInitialWidth(int initialWidth)
          Sets the initial width of the window.
 void setMaskType(ModalWindow.MaskType mask)
          Sets the mask type of the window.
 void setMinimalHeight(int minimalHeight)
          Sets the minimal height of window.
 void setMinimalWidth(int minimalWidth)
          Sets the minimal width of window.
 void setPageCreator(ModalWindow.PageCreator creator)
          Sets the ModalWindow.PageCreator instance.
 void setPageMapName(java.lang.String pageMapName)
          Sets the name of the page ma for the content page.
 void setResizable(boolean resizable)
          Sets whether the user will be able to resize the window.
 void setTitle(IModel title)
          Sets the title of window.
 void setTitle(java.lang.String title)
          Sets the title of window.
 void setUseInitialHeight(boolean useInitialHeight)
          Sets whether to use initial height or preserve the real content height.
 void setWidthUnit(java.lang.String widthUnit)
          Sets the CSS unit used for initial window width.
 void 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
 
Methods inherited from class org.apache.wicket.MarkupContainer
add, addOrReplace, autoAdd, autoAdd, contains, findMarkupStream, get, getAssociatedMarkupStream, getMarkupStream, hasAssociatedMarkup, internalAdd, isTransparentResolver, iterator, iterator, newMarkupResourceStream, onRender, remove, removeAll, renderAll, renderAssociatedMarkup, renderComponentTagBody, replace, setMarkupStream, setModel, size, toString, toString, visitChildren, visitChildren
 
Methods inherited from class org.apache.wicket.Component
add, addStateChange, afterRender, beforeRender, callOnBeforeRenderIfNotVisible, checkComponentTag, checkComponentTagAttribute, checkHierarchyChange, continueToOriginalDestination, debug, detach, detachBehaviors, detachModel, detachModels, determineVisibility, error, exceptionMessage, fatal, findPage, findParent, findParentWithAssociatedMarkup, getApplication, getBehaviors, getBehaviors, getBehaviorsRawList, getClassRelativePath, getComponentBorder, getConverter, getConverter, getEscapeModelStrings, getFeedbackMessage, getFlag, getFlag, getId, getInnermostModel, getInnermostModel, getLocale, getLocalizer, getMarkupAttributes, getMarkupId, getMarkupId, getMetaData, getModel, getModelComparator, getModelObject, getModelObjectAsString, getModelObjectAsString, getOutputMarkupId, getOutputMarkupPlaceholderTag, getPage, getPageFactory, 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, isIgnoreAttributeModifier, isRenderAllowed, isStateless, isVersioned, isVisibilityAllowed, isVisible, isVisibleInHierarchy, locateMarkupStream, markAttached, markRendering, modelChanged, modelChanging, newPage, newPage, onAfterRender, onAttach, onBeginRequest, onEndRequest, onModelChanged, onModelChanging, prepareForRender, redirectToInterceptPage, remove, remove, render, render, renderComponent, renderComponent, renderComponentTag, rendered, replaceComponentTagBody, replaceWith, sameInnermostModel, sameInnermostModel, setAuto, setComponentBorder, setEnabled, setEscapeModelStrings, setFlag, setFlag, setIgnoreAttributeModifier, setMarkupId, setMetaData, setModelObject, 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 java.lang.String CSS_CLASS_BLUE
CSS class for window with blue border.

See Also:
Constant Field Values

CSS_CLASS_GRAY

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

See Also:
Constant Field Values
Constructor Detail

ModalWindow

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

Parameters:
id - Id of component
Method Detail

isShown

public boolean isShown()
Is this window currently showing.

Returns:
the shown

setPageMapName

public void setPageMapName(java.lang.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

getPageMapName

public java.lang.String getPageMapName()
Returns the page map name.

Returns:
The page map name.

setPageCreator

public void 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

setCloseButtonCallback

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

Parameters:
callback - Callback instance

setWindowClosedCallback

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

Parameters:
callback - Callback instance

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.

getContentId

public java.lang.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 void 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.

getMinimalWidth

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

Returns:
Minimal width of window

setMinimalHeight

public void 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

getMinimalHeight

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

Returns:
Minimal height of window

setCssClassName

public void setCssClassName(java.lang.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 -

getCssClassName

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

Returns:
CSS class name

setInitialWidth

public void 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

getInitialWidth

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

Returns:
Initial height of the window

setInitialHeight

public void 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

getInitialHeight

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

Returns:
Initial height of the window

setUseInitialHeight

public void 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

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 void setResizable(boolean resizable)
Sets whether the user will be able to resize the window.

Parameters:
resizable - Whether the window is resizable

isResizable

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

Returns:
True if the window is resizable, false otherwise

setWidthUnit

public void setWidthUnit(java.lang.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.

getWidthUnit

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

Returns:
CSS unit for initial window width.

setHeightUnit

public void setHeightUnit(java.lang.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.

getHeightUnit

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

Returns:
CSS unit for initial window height.

setCookieName

public void setCookieName(java.lang.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

getCookieName

public java.lang.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 void setTitle(java.lang.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

setTitle

public void setTitle(IModel 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

getTitle

public IModel getTitle()
Returns the title of the window.

Returns:
Title of the window

setMaskType

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

Parameters:
mask - The mask type

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()

onComponentTag

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

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

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 void setContent(Component component)
Sets the content of the modal window.

Parameters:
component -

postProcessSettings

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

Parameters:
settings -
Returns:
settings javascript

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 Component


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