Exemplo n.º 1
0
 public static void writeFacetOrAttr(
     ResponseWriter writer,
     FacesContext context,
     UIComponent component,
     String attr,
     String facetName)
     throws IOException {
   writeFacetOrAttr(writer, context, component, attr, component.getFacet(facetName));
 }
Exemplo n.º 2
0
 protected void processColumnHeader(
     FacesContext fc, OutputTypeHandler outputHandler, UIComponent uiColumn, int colIndex) {
   UIComponent headerComp = uiColumn.getFacet("header");
   if (headerComp != null) {
     String headerText = encodeParentAndChildrenAsString(fc, headerComp);
     if (headerText != null) {
       outputHandler.writeHeaderCell(headerText, colIndex);
     }
   }
 }
  /**
   * @param component Component from which to return a facet
   * @param name Name of the desired facet
   * @return the specified facet from the specified component, but <strong>only</strong> if its
   *     <code>rendered</code> property is set to <code>true</code>.
   */
  protected UIComponent getFacet(UIComponent component, String name) {

    UIComponent facet = null;
    if (component.getFacetCount() > 0) {
      facet = component.getFacet(name);
      if ((facet != null) && !facet.isRendered()) {
        facet = null;
      }
    }
    return (facet);
  }
Exemplo n.º 4
0
  @Override
  public void encodeEnd(FacesContext context, UIComponent component) throws IOException {
    ResponseWriter writer = context.getResponseWriter();

    // Last facet
    UIComponent last = component.getFacet("last");
    if (last != null) {
      last.encodeAll(context);
    }

    writer.endElement("head");
  }
Exemplo n.º 5
0
 protected void processColumnFooter(
     FacesContext fc,
     OutputTypeHandler outputHandler,
     UIComponent uiColumn,
     int colIndex,
     int countOfRowsDisplayed) {
   UIComponent footerComp = uiColumn.getFacet("footer");
   if (footerComp != null) {
     Object output = encodeParentAndChildrenAsString(fc, footerComp);
     if (output != null) {
       outputHandler.writeFooterCell(output, colIndex, countOfRowsDisplayed);
     }
   }
 }
  public static UIComponent findFacet(
      FacesContext context, ServletRequest req, UIComponent parent, String facetName)
      throws Exception {
    if (context == null) FacesContext.getCurrentInstance();

    if (parent == null) {
      UIComponentClassicTagBase parentTag =
          (UIComponentClassicTagBase) req.getAttribute("caucho.jsf.parent");

      parent = parentTag.getComponentInstance();
    }

    if (parent != null) return parent.getFacet(facetName);
    else return null;
  }
  public static void addFacetOrAttributeAsOption(
      String name, Map<String, Object> options, FacesContext facesContext, UIComponent component) {

    UIComponent facet = component.getFacet(name);
    if (facet != null && facet.isRendered()) {
      ResponseWriter originalResponseWriter = facesContext.getResponseWriter();
      try {
        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
        PrintWriter printWriter = new PrintWriter(outputStream);
        ResponseWriter newResponseWriter =
            facesContext.getRenderKit().createResponseWriter(printWriter, null, null);
        facesContext.setResponseWriter(newResponseWriter);
        facet.encodeAll(facesContext);
        printWriter.flush();
        String value = new String(outputStream.toByteArray());
        options.put(name, value);
      } catch (IOException e) {
        throw new FacesException(
            "Can't encode facet '"
                + name
                + "' of component '"
                + component.getClass().getName()
                + "'",
            e);
      } finally {
        facesContext.setResponseWriter(originalResponseWriter);
      }
      return;
    }

    Object attribute = component.getAttributes().get(name);
    if (attribute != null) {
      options.put(name, attribute.toString());
      return;
    }
  }
Exemplo n.º 8
0
  @Override
  public void encodeBegin(FacesContext context, UIComponent component) throws IOException {
    ResponseWriter writer = context.getResponseWriter();
    ConfigContainer cc = RequestContext.getCurrentInstance().getApplicationContext().getConfig();
    ProjectStage projectStage = context.getApplication().getProjectStage();
    writer.startElement("head", component);

    // First facet
    UIComponent first = component.getFacet("first");
    if (first != null) {
      first.encodeAll(context);
    }

    writer.write("<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\"/>");

    String theme = resolveTheme(context);
    if (theme == null) {
      renderCSS(context, "mobile/jquery-mobile.css", "primefaces");
    } else {
      renderCSS(context, "theme.css", "primefaces-" + theme);
      renderCSS(context, "mobile/jquery-mobile-icons.css", "primefaces");
      renderCSS(context, "mobile/jquery-mobile-structure.css", "primefaces");
    }

    renderCSS(context, "mobile/primefaces-mobile.css", "primefaces");

    if (cc.isFontAwesomeEnabled()) {
      renderCSS(context, "fa/font-awesome.css", "primefaces");
    }

    renderJS(context, "jquery/jquery.js", "primefaces");

    writer.startElement("script", null);
    writer.writeAttribute("type", "text/javascript", null);
    writer.write("$(document).on('mobileinit', function(){");
    writer.write("$.mobile.ajaxEnabled = false;");
    writer.write("$.mobile.pushStateEnabled = false;");
    writer.write("$.mobile.page.prototype.options.domCache = true;");

    UIComponent init = component.getFacet("init");
    if (init != null) {
      init.encodeAll(context);
    }

    writer.write("});");
    writer.endElement("script");

    renderJS(context, "mobile/jquery-mobile.js", "primefaces");
    renderJS(context, "primefaces-mobile.js", "primefaces");

    // Registered Resources
    UIViewRoot viewRoot = context.getViewRoot();
    for (UIComponent resource : viewRoot.getComponentResources(context, "head")) {
      boolean shouldRender = true;
      Map<String, Object> attrs = resource.getAttributes();
      String library = (String) attrs.get("library");

      if (library != null && library.equals("primefaces")) {
        String resourceName = (String) attrs.get("name");
        if (resourceName.startsWith("jquery") || resourceName.startsWith("primefaces")) {
          shouldRender = false;
        }
      }

      if (shouldRender) {
        resource.encodeAll(context);
      }
    }

    if (cc.isLegacyWidgetNamespace()) {
      writer.startElement("script", null);
      writer.writeAttribute("type", "text/javascript", null);
      writer.write("PrimeFaces.settings.legacyWidgetNamespace = true;");
      writer.endElement("script");
    }

    if (!projectStage.equals(ProjectStage.Production)) {
      writer.write("PrimeFaces.settings.projectStage='" + projectStage.toString() + "';");
    }
  }
  @Override
  protected void getEndTextToRender(
      FacesContext context, UIComponent component, String currentValue) throws IOException {

    if (!(component instanceof BootInputText))
      throw new IOException("Component must be of type " + BootInputText.class.getName());

    BootInputText text = (BootInputText) component;

    ResponseWriter writer = context.getResponseWriter();
    assert (writer != null);

    String styleClass = text.get("styleClass");
    String type = text.get("type");
    String style = text.get("style");

    String id = component.getClientId(context);
    writer.startElement("div", component);
    writeIdAttributeIfNecessary(context, writer, component);
    if (!UtilityMethods.componentIsDisabled(component)) renderOnchange(context, component);

    if (style != null) writer.writeAttribute("style", style, null);
    writer.writeAttribute("class", "input-group", null);
    writer.write("\n");
    writer.startElement("span", component);
    writer.writeAttribute("class", "input-group-addon", null);
    writer.writeAttribute("id", "span_" + id, null);
    UIComponent labelFacet = component.getFacet("label");
    if (labelFacet != null) {
      labelFacet.encodeAll(context);
    } else {
      String label = text.get("label");
      writer.write(label != null ? label : "");
    }

    writer.endElement("span");
    writer.write("\n");
    writer.startElement("input", component);
    writer.writeAttribute("type", type, null);
    writer.writeAttribute("name", id, "clientId");
    writer.writeAttribute("id", component.getClientId() + "_sub_input", null);
    writer.writeAttribute("aria-describedby", "span_" + id, null);
    String placeholder = text.get("placeholder");
    if (placeholder != null) {
      writer.writeAttribute("placeholder", placeholder, null);
    }

    if ("off".equals(component.getAttributes().get("autocomplete"))) {
      writer.writeAttribute("autocomplete", "off", "autocomplete");
    }

    if (currentValue != null) {
      writer.writeAttribute("value", currentValue, "value");
    }

    writer.writeAttribute(
        "class", "form-control" + (styleClass != null ? " " + styleClass : ""), "styleClass");
    writer.writeAttribute("onchange", "$('#" + id + "').change()", null);

    renderPassThruAttributes(
        context, writer, component, INPUT_ATTRIBUTES, getNonOnChangeBehaviors(component));
    renderXHTMLStyleBooleanAttributes(writer, component);
    writer.endElement("input");
    writer.write("\n");
    writer.endElement("div");
    writer.write("\n");
  }
Exemplo n.º 10
0
  public void encodeBegin(FacesContext context, UIComponent component) throws IOException {
    HttpServletRequest req = (HttpServletRequest) context.getExternalContext().getRequest();

    ResponseWriter writer = context.getResponseWriter();

    if (!renderAsFragment(context)) {
      // The stylesheets and javascripts to include are really the portal's responsibility
      // so get them from the portal through the request attributes.
      // Any tool-specific stylesheets need to be placed after Sakai's base CSS (so that
      // tool-specific overrides can take place), but before the installation's skin CSS
      // (so that the tool can be skinned).
      String headBaseCss = (String) req.getAttribute("sakai.html.head.css.base");
      if (headBaseCss == null || headBaseCss.length() == 0) {
        // include default stylesheet
        headBaseCss =
            "<link href=\"/jsf-resource/css/sakai.css\" type=\"text/css\" rel=\"stylesheet\" media=\"all\" />\n";
      }
      String toolCssHref = (String) RendererUtil.getAttribute(context, component, "toolCssHref");
      if (toolCssHref != null) {
        toolCssHref =
            "<link href=\""
                + toolCssHref
                + "\" type=\"text/css\" rel=\"stylesheet\" media=\"all\" />\n";
      }
      String headSkinCss = (String) req.getAttribute("sakai.html.head.css.skin");
      String headJs = (String) req.getAttribute("sakai.html.head.js");
      String bodyonload = (String) req.getAttribute("sakai.html.body.onload");

      // SAK-23099 - Set the lang tag to the current user's locale.
      Locale locale = LocaleUtil.getLocale(context);

      String lang = locale.getLanguage();

      if (lang == null || lang.equals("")) lang = "en";

      String countryCode = locale.getCountry();
      if (countryCode != null && countryCode.length() > 0) {
        lang += "_" + countryCode;
      }

      writer.write(
          "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n");
      writer.write(
          "<html xmlns=\"http://www.w3.org/1999/xhtml\" lang=\""
              + lang
              + "\" xml:lang=\""
              + lang
              + "\">\n");
      writer.write("<head>\n");
      String title = (String) RendererUtil.getAttribute(context, component, "title");
      if (title != null) {
        writer.write("<title>");
        writer.write(title);
        writer.write("</title>\n");
      }

      writer.write(headBaseCss);
      if (toolCssHref != null) writer.write(toolCssHref);
      if (headSkinCss != null) writer.write(headSkinCss);
      if (headJs != null) writer.write(headJs);

      // Useful to include something in the head
      UIComponent headFacet = component.getFacet("head");
      if (headFacet != null) {
        headFacet.encodeBegin(context);
        headFacet.encodeChildren(context);
        headFacet.encodeEnd(context);
      }

      writer.write("</head>\n");

      writer.write("<body");

      if (bodyonload != null && bodyonload.length() > 0) {
        writer.write(" onload=\"");
        writer.write(bodyonload);
        writer.write("\"");
      }
      writer.write(">\n");
    }

    writer.write("<div class=\"portletBody\">\n");
  }
Exemplo n.º 11
0
 public static boolean hasFacet(UIComponent component, String facetName) {
   return component.getFacet(facetName) != null && component.getFacet(facetName).isRendered();
 }