Esempio n. 1
0
File: Timer.java Progetto: zkoss/zk
 /**
  * Processes an AU request.
  *
  * <p>Default: in addition to what are handled by {@link HtmlBasedComponent#service}, it also
  * handles onOpen.
  *
  * @since 5.0.0
  */
 public void service(org.zkoss.zk.au.AuRequest request, boolean everError) {
   final String cmd = request.getCommand();
   if (cmd.equals(Events.ON_TIMER)) {
     if (!_repeats) _running = false; // Bug 1829397
   }
   super.service(request, everError);
 }
Esempio n. 2
0
File: Timer.java Progetto: zkoss/zk
  // super//
  protected void renderProperties(org.zkoss.zk.ui.sys.ContentRenderer renderer)
      throws java.io.IOException {
    super.renderProperties(renderer);

    render(renderer, "repeats", _repeats);
    if (_delay != 0) renderer.render("delay", _delay);
    if (!_running) renderer.render("running", false);
  }
 @Override
 protected Button createRightCaptionButton(
     final String label,
     final String sClass,
     final HtmlBasedComponent parent,
     final org.zkoss.zk.ui.event.EventListener listener) {
   final Button button = new Button(label);
   button.setSclass(sClass);
   button.addEventListener(Events.ON_CLICK, listener);
   parent.appendChild(button);
   return button;
 }
Esempio n. 4
0
  /**
   * Returns the HTML content representing a page.
   *
   * @param au whether it is caused by asynchronous update
   * @param exec the execution (never null)
   */
  public static final void outPageContent(Execution exec, Page page, Writer out, boolean au)
      throws IOException {
    final Desktop desktop = page.getDesktop();
    final PageCtrl pageCtrl = (PageCtrl) page;
    final Component owner = pageCtrl.getOwner();
    boolean contained = owner == null && exec.isIncluded();
    // a standalone page (i.e., no owner), and being included by
    // non-ZK page (e.g., JSP).
    //
    // Revisit Bug 2001707: OK to use exec.isIncluded() since
    // we use PageRenderer now (rather than Servlet's include)
    // TODO: test again

    // prepare style
    String style = page.getStyle();
    if (style == null || style.length() == 0) {
      style = null;
      String wd = null, hgh = null;
      if (owner instanceof HtmlBasedComponent) {
        final HtmlBasedComponent hbc = (HtmlBasedComponent) owner;
        wd = hbc.getWidth(); // null if not set
        hgh = hbc.getHeight(); // null if not set
      }

      if (wd != null || hgh != null || contained) {
        final StringBuffer sb = new StringBuffer(32);
        HTMLs.appendStyle(sb, "width", wd != null ? wd : "100%");
        HTMLs.appendStyle(sb, "height", hgh != null ? hgh : contained ? null : "100%");
        style = sb.toString();
      }
    }

    RenderContext rc = null, old = null;
    final boolean aupg = exec.isAsyncUpdate(page); // AU this page
    final boolean includedAndPart = owner != null && !aupg;
    // this page is included and rendered with its owner
    final boolean divRequired = !au || includedAndPart;
    final boolean standalone = !au && owner == null;
    if (standalone) {
      rc =
          new RenderContext(
              out, new StringWriter(), desktop.getWebApp().getConfiguration().isCrawlable(), false);
      setRenderContext(exec, rc);
    } else if (owner != null) {
      old = getRenderContext(exec); // store
      final boolean crawlable =
          old != null && old.temp != null && desktop.getWebApp().getConfiguration().isCrawlable();
      setRenderContext(exec, crawlable ? new RenderContext(old.temp, null, true, true) : null);
    }

    // generate div first
    if (divRequired) {
      outDivTemplateBegin(out, page.getUuid());
    }
    if (standalone) { // switch out
      // don't call outDivTemplateEnd yet since rc.temp will be generated before it
      out = new StringWriter();
    } else if (divRequired) {
      outDivTemplateEnd(page, out); // close it now since no rc.temp
    }

    if (includedAndPart) {
      out = new StringWriter();
    } else if (divRequired) {
      // generate JS second
      out.write("\n<script class=\"z-runonce\" type=\"text/javascript\">\n");
    }

    exec.setAttribute(ATTR_DESKTOP_JS_GENED, Boolean.TRUE);
    final int order = ComponentRedraws.beforeRedraw(false);
    final String extra;
    try {
      if (order < 0) {
        if (aupg) out.write('[');
        else {
          out.write(outSpecialJS(desktop));
          out.write(divRequired ? "zkmx(" : "zkx(");
        }
      } else if (order > 0) // not first child
      out.write(',');
      out.write("\n[0,'"); // 0: page
      out.write(page.getUuid());
      out.write("',{");

      final StringBuffer props = new StringBuffer(128);
      final String pgid = page.getId();
      if (pgid.length() > 0) appendProp(props, "id", pgid);
      if (owner != null) {
        appendProp(props, "ow", owner.getUuid());
      } else {
        appendProp(props, "dt", desktop.getId());
        appendProp(props, "cu", getContextURI(exec));
        appendProp(props, "uu", desktop.getUpdateURI(null));
        appendProp(props, "ru", desktop.getRequestPath());
      }
      final String pageWgtCls = pageCtrl.getWidgetClass();
      if (pageWgtCls != null) appendProp(props, "wc", pageWgtCls);
      if (style != null) appendProp(props, "style", style);
      if (!isClientROD(page)) appendProp(props, "z$rod", Boolean.FALSE);
      if (contained) appendProp(props, "ct", Boolean.TRUE);
      out.write(props.toString());
      out.write("},[");

      for (Component root = page.getFirstRoot(); root != null; root = root.getNextSibling())
        ((ComponentCtrl) root).redraw(out);

      out.write("]]");
    } finally {
      extra = ComponentRedraws.afterRedraw();
    }

    if (order < 0) {
      outEndJavaScriptFunc(exec, out, extra, aupg);
    }

    if (standalone) {
      setRenderContext(exec, null);

      StringBuffer sw = ((StringWriter) out).getBuffer();
      out = rc.temp;
      if (divRequired) outDivTemplateEnd(page, out);
      // close tag after temp, but before perm (so perm won't be destroyed)
      Files.write(out, ((StringWriter) rc.perm).getBuffer()); // perm

      // B65-ZK-1836
      Files.write(
          out, new StringBuffer(sw.toString().replaceAll("</(?i)(?=script>)", "<\\\\/"))); // js
    } else if (owner != null) { // restore
      setRenderContext(exec, old);
    }

    if (includedAndPart) {
      ((Includer) owner).setRenderingResult(((StringWriter) out).toString());
    } else if (divRequired) {
      out.write("\n</script>\n");
    }
  }
Esempio n. 5
0
 @Override
 protected void renderProperties(ContentRenderer renderer) throws IOException {
   super.renderProperties(renderer);
   render(renderer, "ctrlKeys", _jsCtrlKeys);
   render(renderer, "autoblur", _autoBlur);
 }