Search in sources :

Example 1 with AbstractAjaxBehavior

use of org.apache.wicket.behavior.AbstractAjaxBehavior in project wicket by apache.

the class AjaxLinkTest method page_2.

/**
 * @throws Exception
 */
@Test
public void page_2() throws Exception {
    executeTest(AjaxPage2.class, "AjaxPage2_ExpectedResult.html");
    Page page = tester.getLastRenderedPage();
    Component ajaxLink = page.get("pageLayout:pageLayout_body:ajaxLink");
    AbstractAjaxBehavior behavior = (AbstractAjaxBehavior) ajaxLink.getBehaviors().get(0);
    executeBehavior(behavior, "AjaxPage2-1_ExpectedResult.html");
}
Also used : Page(org.apache.wicket.Page) Component(org.apache.wicket.Component) AbstractAjaxBehavior(org.apache.wicket.behavior.AbstractAjaxBehavior) Test(org.junit.Test)

Example 2 with AbstractAjaxBehavior

use of org.apache.wicket.behavior.AbstractAjaxBehavior in project webanno by webanno.

the class AjaxDownloadLink method commonInit.

void commonInit() {
    downloadBehavior = new AbstractAjaxBehavior() {

        private static final long serialVersionUID = 3472918725573624819L;

        @Override
        public void onRequest() {
            IResourceStream is = AjaxDownloadLink.this.getModelObject();
            if (is != null) {
                // If no filename has been set explicitly, try to get it from the resource
                String name = filename != null ? filename.getObject() : null;
                if (name == null) {
                    if (is instanceof FileResourceStream) {
                        name = ((FileResourceStream) is).getFile().getName();
                    } else if (is instanceof FileSystemResourceStream) {
                        name = ((FileSystemResourceStream) is).getPath().getFileName().toString();
                    }
                }
                ResourceStreamRequestHandler handler = new ResourceStreamRequestHandler(AjaxDownloadLink.this.getModelObject(), name);
                handler.setContentDisposition(ContentDisposition.ATTACHMENT);
                getComponent().getRequestCycle().scheduleRequestHandlerAfterCurrent(handler);
            }
        }
    };
    add(downloadBehavior);
}
Also used : FileResourceStream(org.apache.wicket.util.resource.FileResourceStream) IResourceStream(org.apache.wicket.util.resource.IResourceStream) FileSystemResourceStream(org.apache.wicket.util.resource.FileSystemResourceStream) ResourceStreamRequestHandler(org.apache.wicket.request.handler.resource.ResourceStreamRequestHandler) AbstractAjaxBehavior(org.apache.wicket.behavior.AbstractAjaxBehavior)

Example 3 with AbstractAjaxBehavior

use of org.apache.wicket.behavior.AbstractAjaxBehavior in project wicket by apache.

the class BaseWicketTester method urlFor.

/**
 * @param link
 * @return Url
 */
public Url urlFor(final AjaxLink<?> link) {
    AbstractAjaxBehavior behavior = WicketTesterHelper.findAjaxEventBehavior(link, "click");
    Url url = Url.parse(behavior.getCallbackUrl().toString(), Charset.forName(request.getCharacterEncoding()));
    return transform(url);
}
Also used : Url(org.apache.wicket.request.Url) AbstractAjaxBehavior(org.apache.wicket.behavior.AbstractAjaxBehavior)

Example 4 with AbstractAjaxBehavior

use of org.apache.wicket.behavior.AbstractAjaxBehavior in project wicket by apache.

the class AjaxLinkTest method renderHomePage_2.

/**
 * @throws Exception
 */
@Test
public void renderHomePage_2() throws Exception {
    executeTest(AjaxLinkWithBorderPage.class, "AjaxLinkWithBorderPageExpectedResult.html");
    Page page = tester.getLastRenderedPage();
    Component ajaxLink = page.get("border:border_body:ajaxLink");
    AbstractAjaxBehavior behavior = (AbstractAjaxBehavior) ajaxLink.getBehaviors().get(0);
    executeBehavior(behavior, "AjaxLinkWithBorderPage-1ExpectedResult.html");
}
Also used : Page(org.apache.wicket.Page) Component(org.apache.wicket.Component) AbstractAjaxBehavior(org.apache.wicket.behavior.AbstractAjaxBehavior) Test(org.junit.Test)

Example 5 with AbstractAjaxBehavior

use of org.apache.wicket.behavior.AbstractAjaxBehavior in project wicket by apache.

the class AjaxLinkTest method fromAjaxRequestToNormalPage.

/**
 * Tests setting the request target to a normal page request from an ajax request.
 */
@Test
public void fromAjaxRequestToNormalPage() {
    tester.startPage(AjaxLinkPageToNormalPage.class);
    tester.assertRenderedPage(AjaxLinkPageToNormalPage.class);
    Page page = tester.getLastRenderedPage();
    Component ajaxLink = page.get("ajaxLink");
    AbstractAjaxBehavior behavior = (AbstractAjaxBehavior) ajaxLink.getBehaviors().get(0);
    tester.executeBehavior(behavior);
    tester.assertRenderedPage(NormalPage.class);
}
Also used : Page(org.apache.wicket.Page) Component(org.apache.wicket.Component) AbstractAjaxBehavior(org.apache.wicket.behavior.AbstractAjaxBehavior) Test(org.junit.Test)

Aggregations

AbstractAjaxBehavior (org.apache.wicket.behavior.AbstractAjaxBehavior)7 Page (org.apache.wicket.Page)5 Test (org.junit.Test)5 Component (org.apache.wicket.Component)3 AjaxLink (org.apache.wicket.ajax.markup.html.AjaxLink)1 Url (org.apache.wicket.request.Url)1 ResourceStreamRequestHandler (org.apache.wicket.request.handler.resource.ResourceStreamRequestHandler)1 FileResourceStream (org.apache.wicket.util.resource.FileResourceStream)1 FileSystemResourceStream (org.apache.wicket.util.resource.FileSystemResourceStream)1 IResourceStream (org.apache.wicket.util.resource.IResourceStream)1