示例#1
0
 public static void renderChild(FacesContext context, UIComponent child) throws IOException {
   AssertionUtil.assertNotNull("context", context);
   AssertionUtil.assertNotNull("child", child);
   if (!child.isRendered()) {
     return;
   }
   child.encodeBegin(context);
   if (child.getRendersChildren()) {
     child.encodeChildren(context);
   } else {
     renderChildren(context, child);
   }
   child.encodeEnd(context);
 }
示例#2
0
  protected void renderChild(FacesContext context, UIComponent child) throws IOException {
    if (!child.isRendered()) {
      return;
    }

    child.encodeBegin(context);

    if (child.getRendersChildren()) {
      child.encodeChildren(context);
    } else {
      renderChildren(context, child);
    }
    child.encodeEnd(context);
  }
示例#3
0
  public static void encodeHeader(
      FacesContext facesContext,
      UIComponent component,
      SelectManyRendererBase renderer,
      String rowClass,
      String cellClass)
      throws IOException {
    ResponseWriter writer = facesContext.getResponseWriter();
    AbstractSelectManyComponent select = (AbstractSelectManyComponent) component;
    Iterator<UIColumn> headers = select.columns();

    if (headers.hasNext()) {
      writer.startElement("tr", component);
      StringBuilder headerClass = new StringBuilder(rowClass);
      if (select.getHeaderClass() != null && !select.getHeaderClass().isEmpty()) {
        if (headerClass.length() > 0) {
          headerClass.append(" ");
        }
        headerClass.append(select.getHeaderClass());
      }

      writer.writeAttribute("class", headerClass, null);
      while (headers.hasNext()) {
        UIColumn header = headers.next();
        writer.startElement("th", component);
        writer.writeAttribute("class", cellClass, null);
        UIComponent facet = header.getFacet("header");
        if (facet != null && facet.isRendered()) {
          facet.encodeBegin(facesContext);
          if (facet.getRendersChildren()) {
            facet.encodeChildren(facesContext);
          } else {
            renderer.renderChildren(facesContext, facet);
          }
          facet.encodeEnd(facesContext);
        }
        writer.endElement("th");
      }
      writer.endElement("tr");
    }
  }
  /**
   * Render nested child components by invoking the encode methods on those components, but only
   * when the <code>rendered</code> property is <code>true</code>.
   *
   * @param context FacesContext for the current request
   * @param component the component to recursively encode
   * @throws IOException if an error occurrs during the encode process
   */
  protected void encodeRecursive(FacesContext context, UIComponent component) throws IOException {

    // suppress rendering if "rendered" property on the component is
    // false.
    if (!component.isRendered()) {
      return;
    }

    // Render this component and its children recursively
    component.encodeBegin(context);
    if (component.getRendersChildren()) {
      component.encodeChildren(context);
    } else {
      Iterator<UIComponent> kids = getChildren(component);
      while (kids.hasNext()) {
        UIComponent kid = kids.next();
        encodeRecursive(context, kid);
      }
    }
    component.encodeEnd(context);
  }
  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");
  }
示例#6
0
 /** Calls a component encodeBegin/encodeChildren/encodeEnd methods. */
 public static void encodeComponent(FacesContext context, UIComponent component)
     throws IOException {
   component.encodeBegin(context);
   component.encodeChildren(context);
   component.encodeEnd(context);
 }
示例#7
0
  /**
   * Write the markup to render a navigation widget. Override this to replace the default navigation
   * widget of link with something else.
   */
  protected void writeNavWidgetMarkup(
      FacesContext context, String clientId, int navActionType, boolean enabled)
      throws IOException {
    ResponseWriter writer = context.getResponseWriter();
    String facetOrientation = NORTH;
    String facetName = null;
    String linkText = null;
    String localLinkText = null;
    UIComponent facet = null;
    boolean isCurrentPage = false;
    boolean isPageNumber = false;

    // Assign values for local variables based on the navActionType
    switch (navActionType) {
      case ACTION_NEXT:
        facetName = "next";
        linkText = "Next";
        break;
      case ACTION_PREVIOUS:
        facetName = "previous";
        linkText = "Previous";
        break;
      default:
        facetName = "number";
        linkText = "" + navActionType;
        isPageNumber = true;
        // heuristic: if navActionType is number, and we are not
        // enabled, this must be the current page.
        if (!enabled) {
          facetName = "current";
          isCurrentPage = true;
        }
        break;
    }

    // leverage any navigation facets we have
    writer.write("\n&nbsp;");
    if (enabled) {
      writer.write("<a " + getAnchorAttrs(context, clientId, navActionType) + ">");
    }

    facet = getFacet(facetName);
    // render the facet pertaining to this widget type in the NORTH
    // and WEST cases.
    if (facet != null) {
      // If we're rendering a "go to the Nth page" link
      if (isPageNumber) {
        // See if the user specified an orientation
        String facetO = (String) getAttributes().get(FACET_MARKUP_ORIENTATION_ATTR);
        if (facet != null) {
          facetOrientation = facetO;
          // verify that the orientation is valid
          if (!(facetOrientation.equalsIgnoreCase(NORTH)
              || facetOrientation.equalsIgnoreCase(SOUTH)
              || facetOrientation.equalsIgnoreCase(EAST)
              || facetOrientation.equalsIgnoreCase(WEST))) {
            facetOrientation = NORTH;
          }
        }
      }

      // output the facet as specified in facetOrientation
      if (facetOrientation.equalsIgnoreCase(NORTH) || facetOrientation.equalsIgnoreCase(EAST)) {
        facet.encodeBegin(context);
        if (facet.getRendersChildren()) {
          facet.encodeChildren(context);
        }
        facet.encodeEnd(context);
      }
      // The difference between NORTH and EAST is that NORTH
      // requires a <br>.
      if (facetOrientation.equalsIgnoreCase(NORTH)) {
        writer.startElement("br", null); // PENDING(craigmcc)
        writer.endElement("br");
      }
    }

    // if we have a facet, only output the link text if
    // navActionType is number
    if (null != facet) {
      if (navActionType != ACTION_NEXT && navActionType != ACTION_PREVIOUS) {
        writer.write(linkText);
      }
    } else {
      if (enabled) {
        writer.write(linkText);
      } else {
        writer.startElement("b", null); // PENDING(craigmcc)
        writer.write(linkText);
        writer.endElement("b");
      }
    }

    // output the facet in the EAST and SOUTH cases
    if (null != facet) {
      if (facetOrientation.equalsIgnoreCase(SOUTH)) {
        writer.startElement("br", null); // PENDING(craigmcc)
        writer.endElement("br");
      }
      // The difference between SOUTH and WEST is that SOUTH
      // requires a <br>.
      if (facetOrientation.equalsIgnoreCase(SOUTH) || facetOrientation.equalsIgnoreCase(WEST)) {
        facet.encodeBegin(context);
        if (facet.getRendersChildren()) {
          facet.encodeChildren(context);
        }
        facet.encodeEnd(context);
      }
    }

    if (enabled) {
      writer.write("</a>");
    }
  }