Ejemplo n.º 1
0
  @Override
  public void encodeEnd(FacesContext context, UIComponent component) throws IOException {
    Map<String, String> params = context.getExternalContext().getRequestParameterMap();
    AccordionPanel acco = (AccordionPanel) component;

    if (acco.isContentLoadRequest(context)) {
      String var = acco.getVar();
      String clientId = acco.getClientId(context);

      if (var == null) {
        String tabClientId = params.get(clientId + "_newTab");
        Tab tabToLoad = acco.findTab(tabClientId);
        tabToLoad.encodeAll(context);
        tabToLoad.setLoaded(true);
      } else {
        int index = Integer.parseInt(params.get(clientId + "_tabindex"));
        acco.setIndex(index);
        acco.getChildren().get(0).encodeAll(context);
        acco.setIndex(-1);
      }
    } else {
      encodeMarkup(context, acco);
      encodeScript(context, acco);
    }
  }
Ejemplo n.º 2
0
  protected void encodeTab(
      FacesContext context,
      AccordionPanel accordionPanel,
      Tab tab,
      boolean active,
      boolean dynamic,
      boolean rtl)
      throws IOException {
    ResponseWriter writer = context.getResponseWriter();

    String headerClass =
        active ? AccordionPanel.ACTIVE_TAB_HEADER_CLASS : AccordionPanel.TAB_HEADER_CLASS;
    headerClass = tab.isDisabled() ? headerClass + " ui-state-disabled" : headerClass;
    headerClass =
        tab.getTitleStyleClass() == null
            ? headerClass
            : headerClass + " " + tab.getTitleStyleClass();
    String iconClass =
        active
            ? AccordionPanel.ACTIVE_TAB_HEADER_ICON_CLASS
            : (rtl
                ? AccordionPanel.TAB_HEADER_ICON_RTL_CLASS
                : AccordionPanel.TAB_HEADER_ICON_CLASS);
    String contentClass =
        active
            ? AccordionPanel.ACTIVE_TAB_CONTENT_CLASS
            : AccordionPanel.INACTIVE_TAB_CONTENT_CLASS;
    UIComponent titleFacet = tab.getFacet("title");
    String title = tab.getTitle();
    String tabindex = tab.isDisabled() ? "-1" : accordionPanel.getTabindex();

    // header container
    writer.startElement("div", null);
    writer.writeAttribute("class", headerClass, null);
    writer.writeAttribute("role", "tab", null);
    writer.writeAttribute("aria-expanded", String.valueOf(active), null);
    writer.writeAttribute("aria-selected", String.valueOf(active), null);
    writer.writeAttribute("aria-label", tab.getAriaLabel(), null);
    writer.writeAttribute("tabindex", tabindex, null);
    if (tab.getTitleStyle() != null) writer.writeAttribute("style", tab.getTitleStyle(), null);
    if (tab.getTitletip() != null) writer.writeAttribute("title", tab.getTitletip(), null);

    // icon
    writer.startElement("span", null);
    writer.writeAttribute("class", iconClass, null);
    writer.endElement("span");

    if (titleFacet != null) titleFacet.encodeAll(context);
    else if (title != null) writer.writeText(title, null);
    else writer.write("&nbsp;");

    writer.endElement("div");

    // content
    writer.startElement("div", null);
    writer.writeAttribute("id", tab.getClientId(context), null);
    writer.writeAttribute("class", contentClass, null);
    writer.writeAttribute("role", "tabpanel", null);
    writer.writeAttribute("aria-hidden", String.valueOf(!active), null);

    if (dynamic) {
      if (active) {
        tab.encodeAll(context);
        tab.setLoaded(true);
      }
    } else tab.encodeAll(context);

    writer.endElement("div");
  }