[
https://issues.apache.org/jira/browse/WICKET-12?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12597057#action_12597057
]
Maurice Marrink commented on WICKET-12:
---------------------------------------
I recently needed modalwindow to open up on a normal request too, here is what
i did:
private static final class ScreenSaverWindow extends ModalWindow
{
private static final long serialVersionUID = 1L;
private static final Logger log =
LoggerFactory.getLogger(ScreenSaverWindow.class);
private transient Field showField;
private boolean renderScript = false;
/**
* @param id
*/
@SuppressWarnings("unchecked")
public ScreenSaverWindow(String id)
{
super(id);
initShowField();
}
/**
*
*/
private void initShowField()
{
try
{
showField =
ModalWindow.class.getDeclaredField("shown");
showField.setAccessible(true);
}
catch (SecurityException e)
{
log.error(e.getMessage(), e);
}
catch (NoSuchFieldException e)
{
log.error(e.getMessage(), e);
}
}
/**
* @see
org.apache.wicket.extensions.ajax.markup.html.modal.ModalWindow#onBeforeRender()
*/
@Override
protected void onBeforeRender()
{
if
(SoundScapeSession.getSoundScapeSession().isScreensaverEnabled() && !isShown())
show();
boolean shown = isShown();
super.onBeforeRender();
// fix stupid parent behavior for non ajax requests
if (shown && !isShown())
{
show();
get(getContentId()).setVisible(true);
renderScript = true;
}
}
/**
* @see
org.apache.wicket.markup.html.panel.Panel#renderHead(org.apache.wicket.markup.html.internal.HtmlHeaderContainer)
*/
@Override
public void renderHead(HtmlHeaderContainer container)
{
super.renderHead(container);
// hack to open modal window in non ajax requests too
if (renderScript)
{
try
{
Method m =
ModalWindow.class.getDeclaredMethod("getWindowOpenJavascript");
m.setAccessible(true);
String script = (String) m.invoke(this);
// hack to disable onclose warning for
just this window
container.getHeaderResponse().renderOnDomReadyJavascript(script);
}
catch (SecurityException e)
{
log.error(e.getMessage(), e);
}
catch (NoSuchMethodException e)
{
log.error(e.getMessage(), e);
}
catch (IllegalArgumentException e)
{
log.error(e.getMessage(), e);
}
catch (IllegalAccessException e)
{
log.error(e.getMessage(), e);
}
catch (InvocationTargetException e)
{
log.error(e.getMessage(), e);
}
renderScript = false;
}
}
/**
* shows this modaldialog.
*/
private void show()
{
try
{
if (showField == null)
initShowField();
showField.set(this, true);
}
catch (IllegalArgumentException e)
{
log.error(e.getMessage(), e);
}
catch (IllegalAccessException e)
{
log.error(e.getMessage(), e);
}
}
}
Ok, so it is not pretty, but it works, feel free to use / modify / do whatever
you like with this code.
Note that we store the visibility of this window in our session you can use a
boolean field just as easy
If Matej wants we can modify the modalwindow itself so that we do not need to
hack so much :)
> open Modal Window without AjaxRequestTarget
> -------------------------------------------
>
> Key: WICKET-12
> URL: https://issues.apache.org/jira/browse/WICKET-12
> Project: Wicket
> Issue Type: Improvement
> Components: wicket
> Affects Versions: 1.2.6, 1.3.0-beta1, 2.0 branch (discontinued)
> Reporter: J.W. Janssen
> Assignee: Johan Compagner
> Fix For: 1.5-M1
>
>
> Wicket 1.2.2 included a new Modal Window component. However, this component
> can only be used with a valid AjaxRequestTarget. It would be useful if Modal
> Windows could be opened programmatically at any time without an
> AjaxRequestTarget.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.