You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by "Ryan Holmes (JIRA)" <ji...@apache.org> on 2007/09/11 05:55:29 UTC

[jira] Commented: (WICKET-12) open Modal Window without AjaxRequestTarget

    [ https://issues.apache.org/jira/browse/WICKET-12?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12526342 ] 

Ryan Holmes commented on WICKET-12:
-----------------------------------

A simple workaround is to use JavaScript to call the onclick() method of a link that opens the modal window from a page's onload function. 

The following model ensures that a component is "clicked" only one time, when the page is initially loaded (probably a common use case). 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();
  }
}


Then use it as an onload modifier like so:

// 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.



> 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
>
> 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.