Package org.apache.wicket.protocol.http

Examples of org.apache.wicket.protocol.http.WebRequestCycle


    tester.getApplication().mount(
        new IndexedParamUrlCodingStrategy("/test2", BookmarkableHomePageLinksPage.class,
            "mypagemap"));

    tester.setupRequestAndResponse();
    WebRequestCycle cycle = tester.createRequestCycle();

    PageParameters parameters = new PageParameters();
    parameters.add("0", "Integer0");
    parameters.add("1", "Integer1");
    parameters.add("2", "a:b");

    String url1 = cycle.urlFor(
        new BookmarkablePageRequestTarget(BookmarkableHomePageLinksPage.class, parameters))
        .toString();
    String url2 = cycle.urlFor(
        new BookmarkablePageRequestTarget("mypagemap", BookmarkableHomePageLinksPage.class,
            parameters)).toString();
    assertEquals("test1/Integer0/Integer1/a:b/", url1);
    assertEquals("test2/Integer0/Integer1/a:b/wicket:pageMapName/mypagemap/", url2);

    tester.setupRequestAndResponse();
    tester.getServletRequest().setURL(
        "/WicketTester$DummyWebApplication/WicketTester$DummyWebApplication/" + url1);
    cycle = tester.createRequestCycle();
    IRequestCodingStrategy encoder = cycle.getProcessor().getRequestCodingStrategy();

    RequestParameters requestParameters = encoder.decode(tester.getWicketRequest());

    IRequestTarget target1 = cycle.getProcessor().resolve(cycle, requestParameters);
    if (target1 instanceof BookmarkablePageRequestTarget)
    {
      assertNull(((BookmarkablePageRequestTarget)target1).getPageMapName());
    }
    else
    {
      fail("url: " + url1 + " wasn't resolved to a bookmarkable target: " + target1);
    }
    PageParameters params = ((BookmarkablePageRequestTarget)target1).getPageParameters();
    assertEquals("Integer0", params.getString("0"));
    assertEquals("Integer1", params.getString("1"));
    assertEquals("a:b", params.getString("2"));

    tester.setupRequestAndResponse();
    tester.getServletRequest().setURL(
        "/WicketTester$DummyWebApplication/WicketTester$DummyWebApplication/" + url2);
    cycle = tester.createRequestCycle();
    encoder = cycle.getProcessor().getRequestCodingStrategy();

    requestParameters = encoder.decode(tester.getWicketRequest());

    IRequestTarget target2 = cycle.getProcessor().resolve(cycle, requestParameters);

    if (target2 instanceof BookmarkablePageRequestTarget)
    {
      assertEquals("mypagemap", ((BookmarkablePageRequestTarget)target2).getPageMapName());
    }
View Full Code Here


    requestHandlingOfResourceUrlWithEscapeStringInside();
  }

  private void requestHandlingOfResourceUrlWithEscapeStringInside()
  {
    final WebRequestCycle cycle = tester.setupRequestAndResponse();
    final MockHttpServletRequest request = tester.getServletRequest();
    request.setMethod("GET");
    request.setURL("http://localhost/WicketTester$DummyWebApplication/WicketTester$DummyWebApplication/" +
      expectedResourceUrl());
    tester.processRequestCycle(cycle);
View Full Code Here

     */
    @Override
    public final void renderHead(final IHeaderResponse headResponse)
    {
      Response response = headResponse.getResponse();
      final WebRequestCycle cycle = (WebRequestCycle)RequestCycle.get();
      final IRequestTarget target = cycle.getRequestTarget();

      // we don't want to render this for stateless pages
      if (webPage.isPageStateless())
      {
        return;
      }

      IPageMap pageMap = webPage.getPageMap();
      String name = pageMap.getName();
      if (name == null)
      {
        name = "wicket:default";
      }
      else
      {
        name = name.replace('"', '_');
      }

      Session session = Session.get();

      Session.PageMapAccessMetaData meta = session.getMetaData(Session.PAGEMAP_ACCESS_MDK);
      if (meta == null)
      {
        meta = new Session.PageMapAccessMetaData();
        session.setMetaData(Session.PAGEMAP_ACCESS_MDK, meta);
      }
      boolean firstAccess = meta.add(pageMap);

      if (firstAccess)
      {
        // this is the first access to the pagemap, set window.name
        JavascriptUtils.writeOpenTag(response);
        response.write("if (window.name=='' || window.name.indexOf('wicket') > -1) { window.name=\"");
        response.write("wicket-" + name);
        response.write("\"; }");
        JavascriptUtils.writeCloseTag(response);
      }
      else
      {
        // Here is our trickery to detect whether the current request
        // was made in a new window/ tab, in which case it should go in
        // a different page map so that we don't intermingle the history
        // of those windows
        CharSequence url = null;
        if (target instanceof IBookmarkablePageRequestTarget)
        {
          IBookmarkablePageRequestTarget current = (IBookmarkablePageRequestTarget)target;
          BookmarkablePageRequestTarget redirect = new BookmarkablePageRequestTarget(
            session.createAutoPageMapName(), current.getPageClass(),
            current.getPageParameters());
          url = cycle.urlFor(redirect);
        }
        else
        {
          url = webPage.urlFor(INewBrowserWindowListener.INTERFACE);
        }
View Full Code Here

     * @see org.apache.wicket.markup.html.IHeaderContributor#renderHead(IHeaderResponse)
     */
    public final void renderHead(final IHeaderResponse headResponse)
    {
      Response response = headResponse.getResponse();
      final WebRequestCycle cycle = (WebRequestCycle)RequestCycle.get();
      final IRequestTarget target = cycle.getRequestTarget();

      // we don't want to render this for stateless pages
      if (webPage.isPageStateless())
      {
        return;
      }

      IPageMap pageMap = webPage.getPageMap();
      String name = pageMap.getName();
      if (name == null)
      {
        name = "wicket:default";
      }
      else
      {
        name = name.replace('"', '_');
      }

      Session session = Session.get();

      Session.PageMapAccessMetaData meta = (Session.PageMapAccessMetaData)session.getMetaData(Session.PAGEMAP_ACCESS_MDK);
      if (meta == null)
      {
        meta = new Session.PageMapAccessMetaData();
        session.setMetaData(Session.PAGEMAP_ACCESS_MDK, meta);
      }
      boolean firstAccess = meta.add(pageMap);

      if (firstAccess)
      {
        // this is the first access to the pagemap, set window.name
        JavascriptUtils.writeOpenTag(response);
        response.write("if (window.name=='' || window.name.indexOf('wicket') > -1) { window.name=\"");
        response.write("wicket-" + name);
        response.write("\"; }");
        JavascriptUtils.writeCloseTag(response);
      }
      else
      {
        // Here is our trickery to detect whether the current request
        // was made in a new window/ tab, in which case it should go in
        // a different page map so that we don't intermingle the history
        // of those windows
        CharSequence url = null;
        if (target instanceof IBookmarkablePageRequestTarget)
        {
          IBookmarkablePageRequestTarget current = (IBookmarkablePageRequestTarget)target;
          BookmarkablePageRequestTarget redirect = new BookmarkablePageRequestTarget(
            session.createAutoPageMapName(), current.getPageClass(),
            current.getPageParameters());
          url = cycle.urlFor(redirect);
        }
        else
        {
          url = webPage.urlFor(INewBrowserWindowListener.INTERFACE);
        }
View Full Code Here

   *            an <code>AbstractAjaxBehavior</code> to execute
   */
  public void executeBehavior(final AbstractAjaxBehavior behavior)
  {
    // setupRequestAndResponse();
    WebRequestCycle cycle = createRequestCycle();
    CharSequence url = behavior.getCallbackUrl(false);
    setupRequestAndResponse(true);
    cycle = createRequestCycle();
    getServletRequest().setRequestToRedirectString(url.toString());
    processRequestCycle(cycle);
View Full Code Here

    notNull(failMessage, ajaxEventBehavior);

    // initialize the request only if needed to allow the user to pass
    // request parameters, see
    // WICKET-254
    WebRequestCycle requestCycle;
    if (RequestCycle.get() == null)
    {
      requestCycle = setupRequestAndResponse(true);
    }
    else
    {
      requestCycle = (WebRequestCycle)RequestCycle.get();
    }
    // when the requestcycle is not created via setupRequestAndResponse(true), it can happen
    // that the request is not an ajax request -> we have to set the header manually
    if (!requestCycle.getWebRequest().isAjax())
    {
      HttpServletRequest req = requestCycle.getWebRequest().getHttpServletRequest();
      if (req instanceof MockHttpServletRequest)
      {
        ((MockHttpServletRequest)req).addHeader("Wicket-Ajax", "Yes");
      }
    }
View Full Code Here

    // Make sure a valid cycle is available through RequestCycle.get().
    // The RequestCycle's constructor will attach the new cycle to
    // the threadLocal retrieved by RequestCycle.get().
    // Attached to this cycle must be a valid request and response
    final WebRequestCycle cycle = application.createRequestCycle();

    // Just after init, the requests and responses cookie lists must be
    // empty
    assertNull(getRequestCookies(cycle));
    assertEquals(0, getResponseCookies(cycle).size());
View Full Code Here

   * @param component
   *            the listener to invoke
   */
  public void executeListener(Component component)
  {
    WebRequestCycle cycle = setupRequestAndResponse();
    getServletRequest().setRequestToComponent(component);
    processRequestCycle(cycle);
  }
View Full Code Here

   *            an <code>AbstractAjaxBehavior</code> to execute
   */
  public void executeBehavior(final AbstractAjaxBehavior behavior)
  {
    CharSequence url = behavior.getCallbackUrl(false);
    WebRequestCycle cycle = setupRequestAndResponse(true);
    getServletRequest().setRequestToRedirectString(url.toString());
    processRequestCycle(cycle);
  }
View Full Code Here

      }

      AjaxLink<?> link = (AjaxLink<?>)linkComponent;

      setupRequestAndResponse(true);
      WebRequestCycle requestCycle = createRequestCycle();
      AjaxRequestTarget target = getApplication().newAjaxRequestTarget(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 = getApplication().newAjaxRequestTarget(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)
        {
          AjaxFormSubmitBehavior submitBehavior = (AjaxFormSubmitBehavior)behavior;
          ajaxFormSubmitBehavior = submitBehavior;
        }
      }

      String failMessage = "No form submit behavior found on the submit link. Strange!!";
      notNull(failMessage, ajaxFormSubmitBehavior);

      setupAjaxSubmitRequestParameters(linkComponent, ajaxFormSubmitBehavior);

      WebRequestCycle requestCycle = setupRequestAndResponse(true);

      // Ok, finally we "click" the link
      ajaxFormSubmitBehavior.onRequest();

      // process the request target
View Full Code Here

TOP

Related Classes of org.apache.wicket.protocol.http.WebRequestCycle

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.