There is an open issue about this: http://issues.apache.org/jira/
browse/WICKET-12
Read the discussion for some background and possible solutions.
I needed to do the same thing on a couple of pages. First, I tried
using getWindowOpenJavascript() on the modal window (called via
reflection as it's a private method) to get the needed JS, but I
think I ran into a few issues which I've now forgotten (private
'shown' variable wasn't set?).
What I ended up doing was to use JavaScript to call the onclick()
method of a link that opens the modal window from my page's onload
function. Since the modal window is a JavaScript construct anyway I
don't think using JS for the "auto-open" behavior is weird.
The following model ensures that a component is "clicked" only one
time, when the page is initially loaded (probably a common use case).
If you want to open the modal window on every page load, just check
out the JavaScript and the basic concept. This is written for Wicket
1.2 but a similar approach should work for 1.3.
public class ClickOnceOnLoadModel extends AbstractReadOnlyModel {
private final Component component;
private boolean clicked = false;
public ClickOnceOnLoadModel(Component component) {
this.component = component;
}
@Override
public Object getObject(Component cmp) {
if ( !this.clicked ) {
this.clicked = true;
return getClickJs();
}
return null;
}
private String getClickJs() {
StringBuilder sb = new StringBuilder( 64 );
sb.append( "var e=document.getElementById('" );
sb.append( this.component.getMarkupId() );
sb.append( "');e.onclick();" );
return sb.toString();
}
}
You would use it like this:
// Page constructor
public MyPage() {
getBodyContainer().addOnLoadModifier(
new ClickOnceOnLoadModel( modalWindowOpeningLink ), null );
}
This of course requires a link on your page that opens the same modal
window you want to open automatically. If you really don't want such
a link, you could always hide it with CSS.
If there are more elegant solutions (and I'm sure there are), you'll
probably hear about them soon...
-Ryan
On Sep 9, 2007, at 8:04 PM, Ed _ wrote:
I want to bring up a modal window when I load a page, ie without
clicking a link. I want to use it to prompt the user to enter some
data on the home page before he can proceed. So somehow I have to
enable the show function, how do I do that.
I tried to do something as follows -
FormPanel form = new FormPanel(modal.getContentId(),
StoreBasePath, strId, title);
form.setOutputMarkupId(true);
modal.setContent(form);
modal.setTitle("This is modal window with panel
content.");
modal.setCookieName("modalform");
AjaxRequestTarget target = new AjaxRequestTarget();
modal.show(target);
java.lang.IllegalStateException: No Page found for component
[MarkupContainer [Component id = ModalWindow, page = <No Page>,
path = FormPanel:ModalWindow.ModalWindow]]
at wicket.Component.getPage(Component.java:1037)
at wicket.RequestCycle.urlFor(RequestCycle.java:655)
at wicket.Component.urlFor(Component.java:2307)
at wicket.behavior.AbstractAjaxBehavior.getCallbackUrl
(AbstractAjaxBehavior.java:143)
at wicket.ajax.AbstractDefaultAjaxBehavior.getCallbackScript
(AbstractDefaultAjaxBehavior.java:131)
is there a way to do this.
thanks
_________________________________________________________________
Gear up for Halo® 3 with free downloads and an exclusive offer.
It’s our way of saying thanks for using Windows Live™.
http://gethalo3gear.com?ocid=SeptemberWLHalo3_WLHMTxt_2
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]