问题描述
我使用wicket 1.4.x已经有一段时间了,这里的解决方案效果非常好:
但是当我转移到wicket 1.5时,我根本不知道如何在页面加载时弹出模态窗口。
I was using wicket 1.4.x for some time and solution found here worked pretty well:How to open ModalDialog on PageLoadBut when I moved to wicket 1.5 I simply don't know how make a modalwindow popup on page load.
一段代码如下所示:
private PlainModalWindow tmpPassChange = new PlainModalWindow( "tmp_pass_change" );
tmpPassChange.add( new OpenWindowOnLoadBehavior() );
tmpPassChange.setInitialHeight( 418 );
tmpPassChange.setResizable( false );
tmpPassChange.setMaskType( ModalWindow.MaskType.SEMI_TRANSPARENT );
tmpPassChange.setPageCreator( new ModalWindow.PageCreator()
{
private static final long serialVersionUID = 1L;
public Page createPage()
{
return new TmpPassChange( u, tmpPassChange );
}
} );
add( tmpPassChange );
为了解释,我正在检查页面是否有某个参数。当有一个我在datebase中搜索具有该参数的用户时。当我有一个我想打开PlainModalWindow时,这个窗口是使用css删除样式扩展普通ModalWindow的类,就是这样。加载行为如下所示:
To explain, I'm checking if page has a certain parameter. When there is one I search user with that parameter in datebase. When I have one I'd like to open PlainModalWindow, this window is class extending normal ModalWindow with a css removing style and that's it. The load behavior looks like this:
public class OpenWindowOnLoadBehavior extends AbstractDefaultAjaxBehavior
{
private static final long serialVersionUID = 1L;
@Override
protected void respond( AjaxRequestTarget target )
{
ModalWindow window = (ModalWindow) getComponent();
window.show( target );
}
public void renderHead( IHeaderResponse response )
{
response.renderOnLoadJavaScript( getCallbackScript().toString() );
}
}
正如我上面提到的那样,它在wicket 1.4中有效: (
As I meanioned above, it worked in wicket 1.4 :(
推荐答案
由于我找不到这个问题的答案,我做了一个解决方法。也许它对某人有帮助。首先添加到HTML文件链接(显示:无,所以没有人会看到它):
As I couldn't find answer for this thing I made a workaround. Maybe it helps somebody. First add to HTML file link (display: none so no one will see it) :
<a style="display: none;" wicket:id="openPopup" id="openPopup"/>
创建AjaxLink:
Create an AjaxLink:
AjaxLink openPopup = new AjaxLink("openPopup")
{
@Override
public void onClick(AjaxRequestTarget target)
{
tmpPassChange.show( target );
}
};
add (openPopup);
并且在renderHead方法中检查打开弹出窗口的条件:
And In renderHead method check your conditions for opening popup :
public void renderHead( IHeaderResponse response )
{
String jQueryString = "";
if ( u != null )
{
jQueryString += "jQuery('#openPopup').trigger('click');";
}
response.renderOnLoadJavaScript( jQueryString );
}
希望它会帮助某人,对我有用:)
Hopefully it will help somebody, works for me :)
这篇关于在wicket 1.5中如何在页面上打开模态窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!