@Override
  public void encodeMarkupBegin(FacesContext facesContext, UIComponent uiComponent)
      throws IOException {
    ResponseWriter responseWriter = facesContext.getResponseWriter();

    InputFile inputFile = (InputFile) uiComponent;

    // If the component should render the preview table or the upload progress table, then
    if (inputFile.isShowPreview() || inputFile.isShowProgress()) {

      // Start encoding the outermost <div> element.
      responseWriter.startElement("div", uiComponent);

      String clientId = uiComponent.getClientId(facesContext);
      responseWriter.writeAttribute("id", clientId, "id");
      RendererUtil.encodeStyleable(responseWriter, (Styleable) uiComponent);

      // If the component should render the upload progress table, then format the
      // progress-table.html template
      // and write it to the response.
      if (inputFile.isShowProgress()) {
        encodeProgress(facesContext, responseWriter, uiComponent, clientId);
      }

      // Otherwise, delegate writing to the delegate renderer. Note that this effectively a no-op
      // with Mojarra and
      // MyFaces, since they both delay writing of the entire <input type="file"...> ... </input>
      // element until
      // encodeEnd.
      else {
        super.encodeMarkupBegin(facesContext, uiComponent);
      }
    }

    // Otherwise, delegate writing to the delegate renderer. Note that this effectively a no-op with
    // Mojarra and
    // MyFaces, since they both delay writing of the entire <input type="file"...> ... </input>
    // element until
    // encodeEnd.
    else {
      super.encodeMarkupBegin(facesContext, uiComponent);
    }
  }
  @Override
  public void encodeBegin(FacesContext facesContext, UIComponent uiComponent) throws IOException {

    // Encode the starting <div> element that represents the rich text editor.
    ResponseWriter responseWriter = facesContext.getResponseWriter();
    responseWriter.startElement(StringPool.DIV, uiComponent);

    String clientId = uiComponent.getClientId();
    char separatorChar = UINamingContainer.getSeparatorChar(facesContext);
    String escapedEditorName = clientId.replace(separatorChar, '_').concat("_jsptag");
    responseWriter.writeAttribute(StringPool.ID, clientId, null);
    RendererUtil.encodeStyleable(responseWriter, (Styleable) uiComponent);

    // Encode the starting <textarea> element.
    InputRichText inputRichText = (InputRichText) uiComponent;

    responseWriter.startElement("textarea", uiComponent);
    responseWriter.writeAttribute(StringPool.ID, clientId + "_input", null);
    responseWriter.writeAttribute(StringPool.NAME, escapedEditorName, null);
    responseWriter.writeAttribute(Styleable.STYLE, "display:none;", null);

    // Encode the onblur/onchange/onfocus attributes and any associated client behavior scripts.
    String onblur = inputRichText.getOnblur();
    String onchange = inputRichText.getOnchange();
    String onfocus = inputRichText.getOnfocus();
    Map<String, List<ClientBehavior>> clientBehaviorMap = inputRichText.getClientBehaviors();

    for (String eventName : inputRichText.getEventNames()) {
      List<ClientBehavior> clientBehaviorsForEvent = clientBehaviorMap.get(eventName);

      if (clientBehaviorsForEvent != null) {

        for (ClientBehavior clientBehavior : clientBehaviorsForEvent) {

          ClientBehaviorContext clientBehaviorContext =
              ClientBehaviorContext.createClientBehaviorContext(
                  facesContext, inputRichText, eventName, clientId, null);
          String clientBehaviorScript = clientBehavior.getScript(clientBehaviorContext);

          if (clientBehaviorScript != null) {

            if ("valueChange".equals(eventName) || "change".equals(eventName)) {

              if (onchange != null) {
                clientBehaviorScript = onchange.concat(";").concat(clientBehaviorScript);
                onchange = null;
              }

              responseWriter.writeAttribute("onchange", clientBehaviorScript, null);
            } else if ("blur".equals(eventName)) {

              if (onblur != null) {
                clientBehaviorScript = onblur.concat(";").concat(clientBehaviorScript);
                onblur = null;
              }

              responseWriter.writeAttribute("onblur", clientBehaviorScript, null);
            } else if ("focus".equals(eventName)) {

              if (onfocus != null) {
                clientBehaviorScript = onfocus.concat(";").concat(clientBehaviorScript);
                onfocus = null;
              }

              responseWriter.writeAttribute("onfocus", clientBehaviorScript, null);
            }
          }
        }
      }
    }

    if (onblur != null) {
      responseWriter.writeAttribute("onblur", onblur, null);
    }

    if (onchange != null) {
      responseWriter.writeAttribute("onchange", onchange, null);
    }

    if (onfocus != null) {
      responseWriter.writeAttribute("onfocus", onfocus, null);
    }

    // Encode the value of the component as a child of the textarea element.
    Object value = inputRichText.getValue();

    if (value != null) {
      responseWriter.writeText(value, null);
    }

    // Encode the closing </textarea> element.
    responseWriter.endElement("textarea");

    // Encode the script that contains functions with names specific to this component, so that they
    // can be
    // invoked directly by the JavaScript generated by the JSP tag.
    String formattedTemplate = wysiwygTemplate.format(facesContext, inputRichText);
    responseWriter.startElement(StringPool.SCRIPT, uiComponent);
    responseWriter.writeAttribute(StringPool.TYPE, ContentTypes.TEXT_JAVASCRIPT, null);
    responseWriter.write(formattedTemplate);
    responseWriter.endElement(StringPool.SCRIPT);

    // Begin the JSP tag lifecycle and write the output to the response.
    super.encodeBegin(facesContext, uiComponent);
  }
Пример #3
0
  @Override
  public void encodeBegin(FacesContext facesContext, UIComponent uiComponent) throws IOException {

    ResponseWriter responseWriter = facesContext.getResponseWriter();
    responseWriter.startElement(FIELDSET, uiComponent);

    String clientId = uiComponent.getClientId(facesContext);
    responseWriter.writeAttribute(StringPool.ID, clientId, StringPool.ID);
    responseWriter.writeAttribute(StringPool.NAME, clientId, StringPool.ID);

    Fieldset fieldset = (Fieldset) uiComponent;

    boolean disabled = fieldset.isDisabled();

    if (disabled) {
      responseWriter.writeAttribute(
          StringPool.DISABLED, Boolean.toString(disabled), StringPool.DISABLED);
    }

    RendererUtil.encodeStyleable(responseWriter, fieldset);

    // Encode passthrough attributes.
    String onclick = fieldset.getOnclick();

    if (onclick != null) {
      responseWriter.writeAttribute(ONCLICK, onclick, ONCLICK);
    }

    String ondblclick = fieldset.getOndblclick();

    if (ondblclick != null) {
      responseWriter.writeAttribute(ONDBLCLICK, ondblclick, ONDBLCLICK);
    }

    String onkeydown = fieldset.getOnkeydown();

    if (onkeydown != null) {
      responseWriter.writeAttribute(ONKEYDOWN, onkeydown, ONKEYDOWN);
    }

    String onkeypress = fieldset.getOnkeypress();

    if (onkeypress != null) {
      responseWriter.writeAttribute(ONKEYPRESS, onkeypress, ONKEYPRESS);
    }

    String onkeyup = fieldset.getOnkeyup();

    if (onkeyup != null) {
      responseWriter.writeAttribute(ONKEYUP, onkeyup, ONKEYUP);
    }

    String onmousedown = fieldset.getOnmousedown();

    if (onmousedown != null) {
      responseWriter.writeAttribute(ONMOUSEDOWN, onmousedown, ONMOUSEDOWN);
    }

    String onmousemove = fieldset.getOnmousemove();

    if (onmousemove != null) {
      responseWriter.writeAttribute(ONMOUSEMOVE, onmousemove, ONMOUSEMOVE);
    }

    String onmouseout = fieldset.getOnmouseout();

    if (onmouseout != null) {
      responseWriter.writeAttribute(ONMOUSEOUT, onmouseout, ONMOUSEOUT);
    }

    String onmouseover = fieldset.getOnmouseover();

    if (onmouseover != null) {
      responseWriter.writeAttribute(ONMOUSEOVER, onmouseover, ONMOUSEOVER);
    }

    String onmouseup = fieldset.getOnmouseup();

    if (onmouseup != null) {
      responseWriter.writeAttribute(ONMOUSEUP, onmouseup, ONMOUSEUP);
    }
  }