示例#1
0
  @Override
  public void add(Component... components) {
    for (final Component component : components) {
      Args.notNull(component, "component");

      if (component.getOutputMarkupId() == false && !(component instanceof Page)) {
        throw new IllegalArgumentException(
            "Cannot update component that does not have setOutputMarkupId property set to true. Component: "
                + component.toString());
      } else if (component.getPage() != getPage()) {
        throw new IllegalArgumentException(
            "Cannot update component because its page is not the same as "
                + "the one this handler has been created for. Component: "
                + component.toString());
      }
      add(component, component.getMarkupId());
    }
  }
示例#2
0
 @Override
 public final void focusComponent(Component component) {
   if (component != null && component.getOutputMarkupId() == false) {
     throw new IllegalArgumentException(
         "cannot update component that does not have setOutputMarkupId property set to true. Component: "
             + component.toString());
   }
   final String id = component != null ? ("'" + component.getMarkupId() + "'") : "null";
   appendJavaScript("Wicket.Focus.setFocusOnId(" + id + ");");
 }
  @Override
  protected void writeComponent(
      Response response, String markupId, Component component, String encoding) {
    if (component.getRenderBodyOnly() == true) {
      throw new IllegalStateException(
          "A partial update is not possible for a component that has renderBodyOnly enabled. Component: "
              + component.toString());
    }

    component.setOutputMarkupId(true);

    // Initialize temporary variables
    final Page page = component.findParent(Page.class);
    if (page == null) {
      // dont throw an exception but just ignore this component, somehow
      // it got removed from the page.
      LOG.warn(
          "Component '{}' with markupid: '{}' not rendered because it was already removed from page",
          component,
          markupId);
      return;
    }

    // substitute our encoding response for the old one so we can capture
    // component's markup in a manner safe for transport inside CDATA block
    Response oldResponse = RequestCycle.get().setResponse(bodyBuffer);

    try {
      bodyBuffer.reset();

      page.startComponentRender(component);

      try {
        component.prepareForRender();

        // render any associated headers of the component
        writeHeaderContribution(response, component);
      } catch (RuntimeException e) {
        try {
          component.afterRender();
        } catch (RuntimeException e2) {
          // ignore this one could be a result off.
        }
        bodyBuffer.reset();
        throw e;
      }

      try {
        component.render();
      } catch (RuntimeException e) {
        bodyBuffer.reset();
        throw e;
      }

      page.endComponentRender(component);
    } finally {
      // Restore original response
      RequestCycle.get().setResponse(oldResponse);
    }

    response.write("<component id=\"");
    response.write(markupId);
    response.write("\" ><![CDATA[");
    response.write(encode(bodyBuffer.getContents()));
    response.write("]]></component>");

    bodyBuffer.reset();
  }