Package org.apache.wicket.ajax.markup.html

Examples of org.apache.wicket.ajax.markup.html.AjaxLink


       
        SubmitLink submitLink = new SubmitLink( "submit", form );
        form.add( submitLink );
        form.setDefaultButton(submitLink);
       
        AjaxLink cancelLink = new AjaxLink( "cancel" ) {
            @Override
            public void onClick(AjaxRequestTarget target) {
                setResponsePage(WorkspacePage.class);
            }
        };
View Full Code Here


        return header;
    }

    AjaxLink addUserLink() {
        return new AjaxLink("addUser", new Model()) {

            @Override
            public void onClick(AjaxRequestTarget target) {
                setResponsePage(new NewUserPage());
            }
View Full Code Here

        }
      };
    }
    else if (getLinkType() == LinkType.AJAX)
    {
      return new AjaxLink(id)
      {
        private static final long serialVersionUID = 1L;

        /**
         * @see org.apache.wicket.ajax.markup.html.AjaxLink#onClick(org.apache.wicket.ajax.AjaxRequestTarget)
View Full Code Here

   *
   */
  public void testAssertComponentOnAjaxResponse()
  {
    final Page page = new MockPageWithLink();
    AjaxLink ajaxLink = new AjaxLink(MockPageWithLink.LINK_ID)
    {
      private static final long serialVersionUID = 1L;

      @Override
      public void onClick(AjaxRequestTarget target)
      {
        // Replace the link with a normal Link
        Link link = new Link(MockPageWithLink.LINK_ID)
        {
          private static final long serialVersionUID = 1L;

          @Override
          public void onClick()
          {
            // Do nothing
          }
        };
        link.setOutputMarkupId(true);

        page.replace(link);

        target.addComponent(link);
      }
    };
    ajaxLink.setOutputMarkupId(true);

    page.add(ajaxLink);

    tester.startPage(new ITestPageSource()
    {
View Full Code Here

    labelModel.setObject("Label 1");
    final Label label = new Label(MockPageWithLinkAndLabel.LABEL_ID, labelModel);
    label.setOutputMarkupId(true);

    final Page page = new MockPageWithLinkAndLabel();
    AjaxLink ajaxLink = new AjaxLink(MockPageWithLinkAndLabel.LINK_ID)
    {
      private static final long serialVersionUID = 1L;

      @Override
      public void onClick(AjaxRequestTarget target)
      {
        labelModel.setObject("Label which needs encoding: [] ][");
        target.addComponent(label);
      }
    };
    ajaxLink.setOutputMarkupId(true);

    page.add(ajaxLink);
    ajaxLink.add(label);

    tester.startPage(new ITestPageSource()
    {
      private static final long serialVersionUID = 1L;
View Full Code Here

   * Tests page expired.
   */
  public void testExpirePage()
  {
    tester.startPage(TestExpirePage.class);
    AjaxLink link = (AjaxLink)tester.getComponentFromLastRenderedPage("link");

    // Cannot use executeAjaxEvent or onClick because WicketTester creates
    // an AjaxRequestTarget from scratch
    // tester.executeAjaxEvent(link, "onclick");
    // tester.clickLink("link");

    // FIXME should not be needed
    tester.createRequestCycle();

    // Clear the session to remove the pages
    tester.getWicketSession().invalidateNow();

    // Invoke the call back URL of the ajax event behavior
    String callbackUrl = ((AjaxEventBehavior)link.getBehaviors().get(0)).getCallbackUrl()
      .toString();
    tester.setupRequestAndResponse();

    // Fake an Ajax request
    (tester.getServletRequest()).addHeader("Wicket-Ajax", "Yes");
View Full Code Here

   * Tests internal error page.
   */
  public void testInternalErrorPage()
  {
    tester.startPage(TestErrorPage.class);
    AjaxLink link = (AjaxLink)tester.getComponentFromLastRenderedPage("link");

    // Cannot use executeAjaxEvent or onClick because WicketTester creates
    // an AjaxRequestTarget from scratch
    // tester.executeAjaxEvent(link, "onclick");
    // tester.clickLink("link");

    // FIXME should not be needed
    tester.createRequestCycle();

    // Invoke the call back URL of the ajax event behavior
    String callbackUrl = ((AjaxEventBehavior)link.getBehaviors().get(0)).getCallbackUrl()
      .toString()
      .replaceAll("&", "&");
    tester.setupRequestAndResponse();
    // Fake an Ajax request
    (tester.getServletRequest()).addHeader("Wicket-Ajax", "Yes");
View Full Code Here

      {
        fail("Link " + path + "is an AjaxLink and will " +
          "not be invoked when AJAX (javascript) is disabled.");
      }

      AjaxLink link = (AjaxLink)linkComponent;

      setupRequestAndResponse(true);
      WebRequestCycle requestCycle = createRequestCycle();
      callOnBeginRequest(requestCycle);
      AjaxRequestTarget target = new AjaxRequestTarget(link.getPage());
      requestCycle.setRequestTarget(target);

      link.onClick(target);

      // process the request target
      processRequestCycle(requestCycle);
    }
    // AjaxFallbackLinks is processed like an AjaxLink if isAjax is true
    // If it's not handling of the linkComponent is passed through to the
    // Link.
    else if (linkComponent instanceof AjaxFallbackLink && isAjax)
    {
      AjaxFallbackLink link = (AjaxFallbackLink)linkComponent;

      setupRequestAndResponse(true);
      WebRequestCycle requestCycle = createRequestCycle();
      AjaxRequestTarget target = new AjaxRequestTarget(link.getPage());
      requestCycle.setRequestTarget(target);

      link.onClick(target);

      // process the request target
      processRequestCycle(requestCycle);
    }
    // if the link is an AjaxSubmitLink, we need to find the form
    // from it using reflection so we know what to submit.
    else if (linkComponent instanceof AjaxSubmitLink)
    {
      // If it's not ajax we fail
      if (isAjax == false)
      {
        fail("Link " + path + "is an AjaxSubmitLink and " +
          "will not be invoked when AJAX (javascript) is disabled.");
      }

      AjaxSubmitLink link = (AjaxSubmitLink)linkComponent;

      // We cycle through the attached behaviors and select the
      // LAST matching behavior as the one we handle.
      List<IBehavior> behaviors = link.getBehaviors();
      AjaxFormSubmitBehavior ajaxFormSubmitBehavior = null;
      for (IBehavior behavior : behaviors)
      {
        if (behavior instanceof AjaxFormSubmitBehavior)
        {
View Full Code Here

  {
    tester.startPage(TestExpirePage.class);
    String document = tester.getServletResponse().getDocument();
    assertTrue(document.contains("Click me to get an error"));

    AjaxLink link = (AjaxLink)tester.getComponentFromLastRenderedPage("link");

    // Clear the session to remove the pages
    // tester.getWicketSession().invalidateNow();
    //
    // tester.setCreateAjaxRequest(true);
    // tester.executeAjaxEvent(link, "onclick");
    // tester.clickLink("link");
    //
    // document = tester.getServletResponse().getDocument();
    // assertTrue(document.contains("-"));
    // tester.assertAjaxLocation();

    WebRequestCycle cycle = tester.setupRequestAndResponse(true);
    tester.getWicketSession().invalidateNow();

    // Clear the session to remove the pages
    tester.getWicketSession().invalidateNow();

    // Invoke the call back URL of the ajax event behavior
    String callbackUrl = ((AjaxEventBehavior)link.getBehaviors().get(0)).getCallbackUrl()
      .toString();
    tester.getServletRequest().setURL(callbackUrl);

    // Do not call processRequestCycle() because it throws an
    // exception when getting an error page
View Full Code Here

   * Tests internal error page.
   */
  public void testInternalErrorPage()
  {
    tester.startPage(TestErrorPage.class);
    AjaxLink link = (AjaxLink)tester.getComponentFromLastRenderedPage("link");

    try
    {
      tester.executeAjaxEvent(link, "onclick");
      assertTrue("Excepted an error message to be thrown", false);
View Full Code Here

TOP

Related Classes of org.apache.wicket.ajax.markup.html.AjaxLink

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.