Package org.apache.wicket

Examples of org.apache.wicket.RequestCycle


        return page;
      }
    });

    // Setup the request. It should be a IMultipartWebRequest
    RequestCycle requestCycle = tester.createRequestCycle();
    MockHttpServletRequest servletRequest = tester.getServletRequest();
    servletRequest.setMethod("POST");
    servletRequest.setParameter("form2:hf:fs", "");
    servletRequest.setParameter("wicketState", "");
   
    File tmp = null;
    try {
      // Write out a large text file. We need to make this file reasonably sizable,
      // because things get handled using input streams, and we want to check to make
      // sure they're closed properly if we abort mid-request.
     
      // We create a temp file because we don't want to depend on a file we might not
      // know the path of (e.g. the big DTD this test used previously). This enables
      // us to run the test out of a JAR file if need be, and also with an unknown
      // running directory (e.g. when run from wicket-parent).
      tmp = new File(java.io.File.createTempFile(this.getClass().getName(), ".txt"));
      OutputStream os = new BufferedOutputStream(new FileOutputStream(tmp));
      for (int i = 0; i < 1000; i++)
      {
        os.write("test test test test test\n".getBytes());
      }
      os.close();
   
      // Let's upload the dtd file. It's large enough to avoid being in memory.
      servletRequest.addFile("upload", tmp, "text/plain");
 
      requestCycle.setRequest(new MultipartServletWebRequest(servletRequest, Bytes.MAX));

      // attach manually for the test
      field.attach();
     
      // Get the file upload
View Full Code Here


   *            The url which describes the component path and the interface
   *            to be called.
   */
  private void dispatchEvent(final Page page, final String url)
  {
    RequestCycle rc = RequestCycle.get();
    IRequestCycleProcessor processor = rc.getProcessor();
    final RequestParameters requestParameters = processor.getRequestCodingStrategy().decode(
        new FormDispatchRequest(rc.getRequest(), url));
    IRequestTarget rt = processor.resolve(rc, requestParameters);
    if (rt instanceof ListenerInterfaceRequestTarget)
    {
      ListenerInterfaceRequestTarget interfaceTarget = ((ListenerInterfaceRequestTarget)rt);
      interfaceTarget.getRequestListenerInterface().invoke(page, interfaceTarget.getTarget());
View Full Code Here

          .getResponseRequestEncoding());

      try
      {
        // Create request cycle
        RequestCycle cycle = webApplication.newRequestCycle(request, response);

        try
        {
          // Process request
          cycle.request();
        }
        catch (AbortException e)
        {
          // noop
        }
View Full Code Here

      }

      AjaxLink link = (AjaxLink)linkComponent;

      setupRequestAndResponse();
      RequestCycle requestCycle = createRequestCycle();
      AjaxRequestTarget target = new AjaxRequestTarget();
      requestCycle.setRequestTarget(target);

      link.onClick(target);

      // process the request target
      target.respond(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();
      RequestCycle requestCycle = createRequestCycle();
      AjaxRequestTarget target = new AjaxRequestTarget();
      requestCycle.setRequestTarget(target);

      link.onClick(target);

      // process the request target
      target.respond(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 behaviors = link.getBehaviors();
      AjaxFormSubmitBehavior ajaxFormSubmitBehavior = null;
      for (Iterator iter = behaviors.iterator(); iter.hasNext();)
      {
        Object behavior = iter.next();
        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);

      setupRequestAndResponse();
      RequestCycle requestCycle = createRequestCycle();

      submitAjaxFormSubmitBehavior(ajaxFormSubmitBehavior);

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

      // process the request target
      requestCycle.getRequestTarget().respond(requestCycle);
    }
    // if the link is a normal link (or ResourceLink)
    else if (linkComponent instanceof AbstractLink)
    {
      AbstractLink link = (AbstractLink)linkComponent;
View Full Code Here

   */
  public void testDetachAttachNormalModel() throws Exception
  {
    StringResourceModel model = new StringResourceModel("simple.text", page, wsModel);
    tester.setupRequestAndResponse();
    RequestCycle cycle = new WebRequestCycle(tester.getApplication(),
        tester.getWicketRequest(), tester.getWicketResponse());
    model.getObject();
    Assert.assertNotNull(model.getLocalizer());
    model.detach();
    Assert.assertNull(model.getLocalizer());
View Full Code Here


    };
    StringResourceModel model = new StringResourceModel("simple.text", page, wsDetachModel);
    tester.setupRequestAndResponse();
    RequestCycle cycle = new WebRequestCycle(tester.getApplication(),
        tester.getWicketRequest(), tester.getWicketResponse());
    model.getObject();
    Assert.assertNotNull(model.getLocalizer());
    model.detach();
    // Removed this because getObject() will reattach now...
View Full Code Here

    }

    protected void respond(AjaxRequestTarget target)
    {
      RequestCycle requestCycle = RequestCycle.get();
      boolean save = Boolean.valueOf(requestCycle.getRequest().getParameter("save"))
          .booleanValue();

      if (save)
      {
        editor.processInput();
View Full Code Here

          .getResponseRequestEncoding());

        createRequestContext(request, response);

        // Create request cycle
        final RequestCycle cycle = webApplication.newRequestCycle(request, response);

        try
        {
          // Process request
          cycle.request();

          return cycle.wasHandled();
        }
        catch (AbortException e)
        {
          // noop
        }
View Full Code Here

   *            the <code>Class</code> of the <code>Page</code> to be checked
   * @return true if the given <code>pageClass</code> is mounted, false otherwise
   */
  private boolean isPageMounted(Class<? extends Page> pageClass)
  {
    RequestCycle cycle = RequestCycle.get();
    CharSequence path = getRequestCodingStrategy().pathForTarget(
      new BookmarkablePageRequestTarget(pageClass));
    return path != null;
  }
View Full Code Here

   * @see org.apache.wicket.request.target.coding.AbstractRequestTargetUrlCodingStrategy#matches(java.lang.String)
   */
  @Override
  public boolean matches(String path)
  {
    RequestCycle rc = RequestCycle.get();

    // the null check is necessary, as this method is first time called from WicketFilter when
    // no RequestCycle exists yet
    if (rc != null && ((WebRequest)rc.getRequest()).isAjax())
    {
      // HybridUrlCodingStrategy doesn't make sense for ajax request
      return false;
    }

View Full Code Here

TOP

Related Classes of org.apache.wicket.RequestCycle

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.