Пример #1
0
  protected void encodeChooseButton(FacesContext context, FileUpload fileUpload, boolean disabled)
      throws IOException {
    ResponseWriter writer = context.getResponseWriter();
    String clientId = fileUpload.getClientId(context);
    String cssClass =
        HTML.BUTTON_TEXT_ICON_LEFT_BUTTON_CLASS + " " + FileUpload.CHOOSE_BUTTON_CLASS;
    if (disabled) {
      cssClass += " ui-state-disabled";
    }

    writer.startElement("span", null);
    writer.writeAttribute("class", cssClass, null);

    // button icon
    writer.startElement("span", null);
    writer.writeAttribute("class", HTML.BUTTON_LEFT_ICON_CLASS + " ui-icon-plusthick", null);
    writer.endElement("span");

    // text
    writer.startElement("span", null);
    writer.writeAttribute("class", HTML.BUTTON_TEXT_CLASS, null);
    writer.writeText(fileUpload.getLabel(), "value");
    writer.endElement("span");

    if (!disabled) {
      encodeInputField(context, fileUpload, clientId + "_input");
    }

    writer.endElement("span");
  }
Пример #2
0
  public String getSimpleInputDecodeId(FileUpload fileUpload, FacesContext context) {
    String clientId = fileUpload.getClientId(context);

    if (fileUpload.getMode().equals("simple") && !fileUpload.isSkinSimple()) {
      return clientId;
    } else {
      return clientId + "_input";
    }
  }
Пример #3
0
  protected void encodeAdvancedMarkup(FacesContext context, FileUpload fileUpload)
      throws IOException {
    ResponseWriter writer = context.getResponseWriter();
    String clientId = fileUpload.getClientId(context);
    String style = fileUpload.getStyle();
    String styleClass = fileUpload.getStyleClass();
    styleClass =
        styleClass == null
            ? FileUpload.CONTAINER_CLASS
            : FileUpload.CONTAINER_CLASS + " " + styleClass;
    boolean disabled = fileUpload.isDisabled();

    writer.startElement("div", fileUpload);
    writer.writeAttribute("id", clientId, "id");
    writer.writeAttribute("class", styleClass, styleClass);
    if (style != null) {
      writer.writeAttribute("style", style, "style");
    }

    // buttonbar
    writer.startElement("div", fileUpload);
    writer.writeAttribute("class", FileUpload.BUTTON_BAR_CLASS, null);

    // choose button
    encodeChooseButton(context, fileUpload, disabled);

    if (!fileUpload.isAuto()) {
      encodeButton(
          context,
          fileUpload.getUploadLabel(),
          FileUpload.UPLOAD_BUTTON_CLASS,
          "ui-icon-arrowreturnthick-1-n");
      encodeButton(
          context, fileUpload.getCancelLabel(), FileUpload.CANCEL_BUTTON_CLASS, "ui-icon-cancel");
    }

    writer.endElement("div");

    renderChildren(context, fileUpload);

    // content
    writer.startElement("div", null);
    writer.writeAttribute("class", FileUpload.CONTENT_CLASS, null);

    writer.startElement("table", null);
    writer.writeAttribute("class", FileUpload.FILES_CLASS, null);
    writer.startElement("tbody", null);
    writer.endElement("tbody");
    writer.endElement("table");

    writer.endElement("div");

    writer.endElement("div");
  }
Пример #4
0
  protected void encodeScript(FacesContext context, FileUpload fileUpload) throws IOException {
    String clientId = fileUpload.getClientId(context);
    String update = fileUpload.getUpdate();
    String process = fileUpload.getProcess();
    WidgetBuilder wb = getWidgetBuilder(context);

    if (fileUpload.getMode().equals("advanced")) {
      wb.initWithDomReady("FileUpload", fileUpload.resolveWidgetVar(), clientId);

      wb.attr("auto", fileUpload.isAuto(), false)
          .attr("dnd", fileUpload.isDragDropSupport(), true)
          .attr(
              "update",
              SearchExpressionFacade.resolveClientIds(
                  context, fileUpload, update, SearchExpressionFacade.Options.VISIT_UNRENDERED),
              null)
          .attr(
              "process",
              SearchExpressionFacade.resolveClientIds(
                  context, fileUpload, process, SearchExpressionFacade.Options.VISIT_UNRENDERED),
              null)
          .attr("maxFileSize", fileUpload.getSizeLimit(), Long.MAX_VALUE)
          .attr("fileLimit", fileUpload.getFileLimit(), Integer.MAX_VALUE)
          .attr("invalidFileMessage", fileUpload.getInvalidFileMessage(), null)
          .attr("invalidSizeMessage", fileUpload.getInvalidSizeMessage(), null)
          .attr("fileLimitMessage", fileUpload.getFileLimitMessage(), null)
          .attr("messageTemplate", fileUpload.getMessageTemplate(), null)
          .attr("previewWidth", fileUpload.getPreviewWidth(), 80)
          .attr("disabled", fileUpload.isDisabled(), false)
          .attr("sequentialUploads", fileUpload.isSequential(), false)
          .callback("onstart", "function()", fileUpload.getOnstart())
          .callback("onerror", "function()", fileUpload.getOnerror())
          .callback("oncomplete", "function(args)", fileUpload.getOncomplete());

      if (fileUpload.getAllowTypes() != null) {
        wb.append(",allowTypes:").append(fileUpload.getAllowTypes());
      }
    } else {
      wb.init("SimpleFileUpload", fileUpload.resolveWidgetVar(), clientId)
          .attr("skinSimple", fileUpload.isSkinSimple(), false);
    }

    wb.finish();
  }
Пример #5
0
  protected void encodeSimpleMarkup(FacesContext context, FileUpload fileUpload)
      throws IOException {
    ResponseWriter writer = context.getResponseWriter();
    String clientId = fileUpload.getClientId(context);
    String style = fileUpload.getStyle();
    String styleClass = fileUpload.getStyleClass();

    if (fileUpload.isSkinSimple()) {
      styleClass =
          (styleClass == null)
              ? FileUpload.CONTAINER_CLASS_SIMPLE
              : FileUpload.CONTAINER_CLASS_SIMPLE + " " + styleClass;
      String label = fileUpload.getLabel();
      String buttonClass =
          isValueBlank(label)
              ? HTML.BUTTON_ICON_ONLY_BUTTON_CLASS
              : HTML.BUTTON_TEXT_ICON_LEFT_BUTTON_CLASS;
      if (fileUpload.isDisabled()) {
        buttonClass += " ui-state-disabled";
      }

      writer.startElement("span", fileUpload);
      writer.writeAttribute("id", clientId, "id");
      writer.writeAttribute("class", styleClass, "styleClass");
      if (style != null) {
        writer.writeAttribute("style", style, "style");
      }

      writer.startElement("span", null);
      writer.writeAttribute("class", buttonClass, null);

      // button icon
      writer.startElement("span", null);
      writer.writeAttribute("class", HTML.BUTTON_LEFT_ICON_CLASS + " ui-icon-plusthick", null);
      writer.endElement("span");

      // text
      writer.startElement("span", null);
      writer.writeAttribute("id", clientId + "_label", null);
      writer.writeAttribute("class", HTML.BUTTON_TEXT_CLASS, null);
      if (isValueBlank(label)) {
        writer.write("ui-button");
      } else {
        writer.writeText(label, "value");
      }
      writer.endElement("span");

      encodeInputField(context, fileUpload, fileUpload.getClientId(context));

      writer.endElement("span");

      writer.startElement("span", fileUpload);
      writer.writeAttribute("class", FileUpload.FILENAME_CLASS, null);
      writer.endElement("span");

      writer.endElement("span");
    } else {
      encodeSimpleInputField(
          context, fileUpload, fileUpload.getClientId(context), style, styleClass);
    }
  }
Пример #6
0
 protected void encodeSimpleMarkup(FacesContext context, FileUpload fileUpload)
     throws IOException {
   encodeInputField(context, fileUpload, fileUpload.getClientId(context));
 }