Example usage for org.apache.wicket.ajax AjaxRequestTarget getComponents

List of usage examples for org.apache.wicket.ajax AjaxRequestTarget getComponents

Introduction

In this page you can find the example usage for org.apache.wicket.ajax AjaxRequestTarget getComponents.

Prototype

Collection<? extends Component> getComponents();

Source Link

Document

Returns an unmodifiable collection of all components added to this target

Usage

From source file:com.aplombee.QuickViewTest.java

License:Apache License

/**
 * components not empty  and repeater's parent is added to another component which is added to A.R.T
 *///ww w . j av a 2 s.  c  o  m
@Test(groups = { "wicketTests" })
public void Synchronizer_isParentAdded_1() {

    final AjaxRequestTarget target = Mockito.mock(AjaxRequestTarget.class);
    List cs = new ArrayList();
    Mockito.when(target.getComponents()).thenReturn(cs);
    WebMarkupContainer one = Mockito.mock(WebMarkupContainer.class);
    WebMarkupContainer two = Mockito.mock(WebMarkupContainer.class);
    Label three = Mockito.mock(Label.class);
    cs.add(one);
    cs.add(two);
    cs.add(three);
    final MarkupContainer parent = Mockito.mock(MarkupContainer.class);
    QuickViewBase.Synchronizer synchronizer = new QuickViewBase.Synchronizer(parent) {
        @Override
        protected Boolean addNewChildVisitor(MarkupContainer parent, Component searchFor) {
            return true;
        }

    };
    QuickViewBase.Synchronizer spy = Mockito.spy(synchronizer);
    spy.isParentAddedInAjaxRequestTarget(target);
    Mockito.verify(spy, Mockito.times(1)).addNewChildVisitor(one, parent);
    Mockito.verify(spy, Mockito.never()).addNewChildVisitor(two, parent);

}

From source file:com.aplombee.QuickViewTest.java

License:Apache License

/**
 * components not empty  and repeater's parent is added directly in A.R.T
 *//*ww w .j a  v a  2 s .  c  om*/
@Test(groups = { "wicketTests" })
public void Synchronizer_isParentAdded_2() {
    IDataProvider provider = Mockito.mock(IDataProvider.class);
    final AjaxRequestTarget target = Mockito.mock(AjaxRequestTarget.class);
    List cs = new ArrayList();
    Mockito.when(target.getComponents()).thenReturn(cs);
    final WebMarkupContainer one = Mockito.mock(WebMarkupContainer.class);
    WebMarkupContainer two = Mockito.mock(WebMarkupContainer.class);
    // Label three = Mockito.mock(Label.class);
    cs.add(one);
    cs.add(two);
    WebMarkupContainer parent = Mockito.mock(WebMarkupContainer.class);
    QuickViewBase.Synchronizer synchronizer = new QuickViewBase.Synchronizer(parent) {
        @Override
        protected Boolean addNewChildVisitor(MarkupContainer parent, Component searchFor) {
            return true;
        }

    };
    QuickViewBase.Synchronizer spy = Mockito.spy(synchronizer);
    spy.isParentAddedInAjaxRequestTarget(target);
    Mockito.verify(spy, Mockito.never()).addNewChildVisitor(one, one);
    Mockito.verify(spy, Mockito.never()).addNewChildVisitor(two, one);

}

From source file:com.aplombee.QuickViewTest.java

License:Apache License

/**
 * components is empty  and repeater's parent is added directly in A.R.T
 *//*from   w  w w.  jav  a  2s. c o  m*/
@Test(groups = { "wicketTests" })
public void Synchronizer_isParentAdded_3() {
    IDataProvider provider = Mockito.mock(IDataProvider.class);
    final AjaxRequestTarget target = Mockito.mock(AjaxRequestTarget.class);
    List cs = new ArrayList();
    Mockito.when(target.getComponents()).thenReturn(cs);
    WebMarkupContainer parent = Mockito.mock(WebMarkupContainer.class);
    QuickViewBase.Synchronizer synchronizer = new QuickViewBase.Synchronizer(parent) {
        @Override
        protected Boolean addNewChildVisitor(MarkupContainer parent, Component searchFor) {
            return true;
        }

    };
    QuickViewBase.Synchronizer spy = Mockito.spy(synchronizer);
    spy.isParentAddedInAjaxRequestTarget(target);
    Mockito.verify(spy, Mockito.never()).addNewChildVisitor(Mockito.any(MarkupContainer.class),
            Mockito.any(MarkupContainer.class));
}

From source file:com.mylab.wicket.jpa.ui.pages.select2.AbstractSelect2Choice.java

License:Apache License

@Override
public void onEvent(IEvent<?> event) {
    super.onEvent(event);
    if (event.getPayload() instanceof AjaxRequestTarget) {
        AjaxRequestTarget target = (AjaxRequestTarget) event.getPayload();
        if (target.getComponents().contains(this)) {

            // if this component is being repainted by ajax, directly, we
            // must destroy Select2 so it removes
            // its elements from DOM
            target.prependJavaScript(JQuery.execute("$('#%s').select2('destroy');", getJquerySafeMarkupId()));
        }/*from ww  w. j  a va 2  s.  c om*/
    }
}

From source file:com.socialsite.BasePanel.java

License:Open Source License

/**
 * fires a event with the collection of all the updated dom elements after
 * the wicket ajax response. To subscribe the event call the
 * <code>SocialSite.Ajax.registerPostAjax</code>. Your callback function
 * will be called with a jQuery Wrapped set of all the update dom as the
 * first argument.// w ww . jav  a 2 s. c o  m
 * 
 * NOTE: call this only once after all the components are added to the
 * target
 * 
 * 
 * @param target
 *            ajax target
 */
public void firePostAjaxUpdateEvent(final AjaxRequestTarget target) {
    final StringBuffer script = new StringBuffer(" SocialSite.Ajax.handle([");
    for (final Component component : target.getComponents()) {
        script.append("\"" + component.getMarkupId() + "\",");
    }
    script.append("])");

    target.getHeaderResponse().renderOnDomReadyJavascript(script.toString());
}

From source file:com.vaynberg.wicket.select2.AbstractSelect2Choice.java

License:Apache License

@Override
public void onEvent(IEvent<?> event) {
    super.onEvent(event);

    if (event.getPayload() instanceof AjaxRequestTarget) {

        AjaxRequestTarget target = (AjaxRequestTarget) event.getPayload();

        if (target.getComponents().contains(this)) {

            // if this component is being repainted by ajax, directly, we must destroy Select2 so it removes
            // its elements from DOM

            target.prependJavaScript(JQuery.execute("$('#%s').select2('destroy');", getJquerySafeMarkupId()));
        }//from   ww w  . j  av  a 2s  .  c  o m
    }
}

From source file:gr.interamerican.wicket.ajax.markup.html.form.TestCallbackAjaxButton.java

License:Open Source License

/**
 * Test OnError/*from  w w w  .  j a  va  2  s . co  m*/
 */
@Test
public void testOnError() {
    WicketPage page = new WicketPage();
    AjaxRequestTarget target = new AjaxRequestTarget(page);
    Form<Void> form = new Form<Void>("id"); //$NON-NLS-1$
    FeedbackPanel panel = new FeedbackPanel("panelId"); //$NON-NLS-1$
    button = new CallbackAjaxButton(id, model, action, panel);
    panel.setOutputMarkupId(true);
    button.onError(target, form);
    assertEquals(1, target.getComponents().size());
}

From source file:gr.interamerican.wicket.ajax.markup.html.form.TestCallbackAjaxImageButton.java

License:Open Source License

/**
 * Test OnError//from w w  w. j  a va 2  s .co  m
 */
@Test
public void testOnError() {
    WicketPage page = new WicketPage();
    AjaxRequestTarget target = new AjaxRequestTarget(page);
    Form<Void> form = new Form<Void>("id"); //$NON-NLS-1$
    FeedbackPanel panel = new FeedbackPanel("panelId"); //$NON-NLS-1$
    button = new CallbackAjaxImageButton(id, model, action, panel, ImageType.EDIT.getImage());
    panel.setOutputMarkupId(true);
    button.onError(target, form);
    assertEquals(1, target.getComponents().size());
}

From source file:org.hippoecm.frontend.plugins.yui.layout.WireframeBehavior.java

License:Apache License

@Override
public boolean isRendered() {
    AjaxRequestTarget target = RequestCycle.get().find(AjaxRequestTarget.class);
    if (target != null) {
        Component parent = getComponent();
        while (parent != null && !target.getComponents().contains(parent)) {
            parent = parent.getParent();
        }/*from   w  ww .  j  av a2 s . c  om*/
        if (parent != null) {
            return false;
        }
    } else {
        return false;
    }
    return rendered;
}