/**
   * Sets a parameter for the component with the given path to be used with the next request. NOTE:
   * this method only works when a page was rendered first.
   *
   * @param componentPath path of the component
   * @param value the parameter value to set
   */
  public void setParameterForNextRequest(String componentPath, Object value) {
    if (getLastRenderedPage() == null) {
      Assert.fail("before using this method, at least one page has to be rendered");
    }

    Component c = getComponentFromLastRenderedPage(componentPath);
    if (c == null) {
      Assert.fail("component " + componentPath + " was not found");
      return;
    }

    if (c instanceof FormComponent) {
      getParametersForNextRequest().put(((FormComponent) c).getInputName(), value);
    } else {
      getParametersForNextRequest().put(c.getPath(), value);
    }
  }
  /**
   * Encode a listener interface target.
   *
   * <p>If you override this method to behave different then also {@link
   * #addInterfaceParameters(Request, RequestParameters)} should be overridden to by in sync with
   * that behaviour.
   *
   * @param requestCycle the current request cycle
   * @param requestTarget the target to encode
   * @return the encoded url
   */
  protected CharSequence encode(
      RequestCycle requestCycle, IListenerInterfaceRequestTarget requestTarget) {
    final RequestListenerInterface rli = requestTarget.getRequestListenerInterface();

    // Start string buffer for url
    final AppendingStringBuffer url = new AppendingStringBuffer(64);
    url.append(urlPrefix(requestCycle));
    url.append('?');
    url.append(INTERFACE_PARAMETER_NAME);
    url.append('=');

    // Get component and page for request target
    final Component component = requestTarget.getTarget();
    final Page page = component.getPage();

    // Add pagemap
    final PageMap pageMap = page.getPageMap();
    if (!pageMap.isDefault()) {
      url.append(pageMap.getName());
    }
    url.append(Component.PATH_SEPARATOR);

    // Add path to component
    url.append(component.getPath());
    url.append(Component.PATH_SEPARATOR);

    // Add version
    final int versionNumber = component.getPage().getCurrentVersionNumber();
    if (!rli.getRecordsPageVersion()) {
      url.append(Page.LATEST_VERSION);
    } else if (versionNumber > 0) {
      url.append(versionNumber);
    }
    url.append(Component.PATH_SEPARATOR);

    // Add listener interface
    final String listenerName = rli.getName();
    if (!IRedirectListener.INTERFACE.getName().equals(listenerName)) {
      url.append(listenerName);
    }

    return requestCycle.getOriginalResponse().encodeURL(url);
  }