Package org.apache.myfaces.tobago.webapp

Examples of org.apache.myfaces.tobago.webapp.TobagoResponseWriter


    HtmlRendererUtil.createHeaderAndBodyStyles(facesContext, data);

    final String sheetId = data.getClientId(facesContext);
    HtmlStyleMap sheetStyle = (HtmlStyleMap) data.getAttributes().get(TobagoConstants.ATTR_STYLE);

    TobagoResponseWriter writer = HtmlRendererUtil.getTobagoResponseWriter(facesContext);

    // Outher list div
    writer.startElement(HtmlConstants.DIV, null);
    writer.writeIdAttribute(sheetId + "_outer_div");
    writer.writeClassAttribute("tobago-simpleSheet-content");
    writer.writeStyleAttribute(sheetStyle);
    UICommand clickAction = null;
    UICommand dblClickAction = null;
    int columnSelectorIndex = -1;
    int i = 0;
    for (UIComponent child : (List<UIComponent>) data.getChildren()) {
      if (child instanceof UIColumnEvent) {
        UIColumnEvent columnEvent = (UIColumnEvent) child;
        if (columnEvent.isRendered()) {
          UIComponent selectionChild = (UIComponent) child.getChildren().get(0);
          if (selectionChild != null && selectionChild instanceof UICommand && selectionChild.isRendered()) {
            UICommand action = (UICommand) selectionChild;
            if ("click".equals(columnEvent.getEvent())) {
              clickAction = action;
            }
            if ("dblclick".equals(columnEvent.getEvent())) {
              dblClickAction = action;
            }
          }
        }
      } else if (child instanceof UIColumnSelector) {
        columnSelectorIndex = i;
      }
      i++;
    }

    renderSheet(facesContext, data, (clickAction != null || dblClickAction != null));

    writer.endElement(HtmlConstants.DIV);

    ResourceManager resourceManager = ResourceManagerFactory.getResourceManager(facesContext);
    UIViewRoot viewRoot = facesContext.getViewRoot();
    String contextPath = facesContext.getExternalContext().getRequestContextPath();
View Full Code Here


  @SuppressWarnings(value = "unchecked")
  protected void renderSheet(FacesContext facesContext, UIData data, boolean hasClickAction) throws IOException {


    TobagoResponseWriter writer
        = (TobagoResponseWriter) facesContext.getResponseWriter();
    String sheetId = data.getClientId(facesContext);
    SheetState sheetState = data.getSheetState(facesContext);
    List<UIColumn> renderedColumnList = data.getRenderedColumns();

    HtmlStyleMap sheetStyle = (HtmlStyleMap) data.getAttributes().get(TobagoConstants.ATTR_STYLE);
    Integer sheetHeight = HtmlRendererUtil.getStyleAttributeIntValue(sheetStyle, "height");
    if (sheetHeight == null) {
      // FIXME: nullpointer if height not defined
      LOG.error("no height in parent container, setting to 100");
      sheetHeight = 100;
    }
    int footerHeight = (Integer) data.getAttributes().get(TobagoConstants.ATTR_FOOTER_HEIGHT);

    HtmlStyleMap bodyStyle = (HtmlStyleMap) data.getAttributes().get(TobagoConstants.ATTR_STYLE_BODY);
    HtmlRendererUtil.replaceStyleAttribute(data, TobagoConstants.ATTR_STYLE_BODY, "height",
        (sheetHeight - footerHeight));


    List<Integer> columnWidths = data.getWidthList();
    writer.startElement(HtmlConstants.INPUT, null);
    writer.writeIdAttribute(sheetId + WIDTHS_POSTFIX);
    writer.writeNameAttribute(sheetId + WIDTHS_POSTFIX);
    writer.writeAttribute(HtmlAttributes.TYPE, "hidden", false);
    writer.writeAttribute(HtmlAttributes.VALUE, StringUtils.toString(columnWidths), false);
    writer.endElement(HtmlConstants.INPUT);

    writer.startElement(HtmlConstants.INPUT, null);
    writer.writeIdAttribute(sheetId + SCROLL_POSTFIX);
    writer.writeNameAttribute(sheetId + SCROLL_POSTFIX);
    writer.writeAttribute(HtmlAttributes.TYPE, "hidden", false);
    Integer[] scrollPosition = data.getScrollPosition();
    if (scrollPosition != null) {
      String scroll = scrollPosition[0] + ";" + scrollPosition[1];
      writer.writeAttribute(HtmlAttributes.VALUE, scroll, false);
    } else {
      writer.writeAttribute(HtmlAttributes.VALUE, "", false);
    }
    writer.endElement(HtmlConstants.INPUT);
    List<Integer> selectedRows = sheetState.getSelectedRows();
    if (!UIData.NONE.equals(data.getSelectable())) {
      writer.startElement(HtmlConstants.INPUT, null);
      writer.writeIdAttribute(sheetId + SELECTED_POSTFIX);
      writer.writeNameAttribute(sheetId + SELECTED_POSTFIX);
      writer.writeAttribute(HtmlAttributes.TYPE, "hidden", false);
      writer.writeAttribute(HtmlAttributes.VALUE, StringUtils.toString(selectedRows), false);
      writer.endElement(HtmlConstants.INPUT);
    }
    ResourceManager resourceManager = ResourceManagerFactory.getResourceManager(facesContext);
    UIViewRoot viewRoot = facesContext.getViewRoot();
    String contextPath = facesContext.getExternalContext().getRequestContextPath();

    //String checkedImage = contextPath + resourceManager.getImage(viewRoot, "image/sheetChecked.gif");
    //String uncheckeImage = contextPath + resourceManager.getImage(viewRoot, "image/sheetUnchecked.gif");
    String selectorDisabled = contextPath + resourceManager.getImage(viewRoot, "image/sheetUncheckedDisabled.gif");
    String unchecked = contextPath + resourceManager.getImage(viewRoot, "image/sheetUnchecked.gif");
    // Outer list div
    writer.startElement(HtmlConstants.DIV, null);
    writer.writeIdAttribute(sheetId + "_data_div");
    writer.writeClassAttribute("tobago-simpleSheet-list");
    writer.writeStyleAttribute(bodyStyle);

    int top = 20;


    boolean odd = false;
    final int last = data.getFirst() + data.getRows();
    for (int row = data.getFirst(); row < last; row++) {
      data.setRowIndex(row);
      if (!data.isRowAvailable()) {
        break;
      }

      odd = !odd;
      final String rowClass = odd ? "tobago-sheet-content-odd " : "tobago-sheet-content-even ";

      //TODO make markup toago compatible
      String[] rowMarkups = (String[]) data.getAttributes().get("rowMarkup");
      String rowMarkup = "";
      if (rowMarkup != null) {
        rowMarkup = " " + org.apache.commons.lang.StringUtils.join(rowMarkups, " ");
      }

      writer.startElement(HtmlConstants.DIV, null);
      writer.writeClassAttribute("tobago-simpleSheet-row " + rowClass + rowMarkup);
      writer.writeIdAttribute(sheetId + "_data_tr_" + row);
      writer.writeAttribute(HtmlAttributes.STYLE, "top: "+ top+ "px; left: 0px;", false);
      writer.flush();

      int columnIndex = -1;
      int currentLeft = 0;
      for (UIColumn column : renderedColumnList) {
        columnIndex++;
        writer.startElement(HtmlConstants.DIV, null);
        writer.writeClassAttribute("tobago-simpleSheet-cell");
        // todo cell markup
           // + (rowSelected ? " tobabo-simpleSheet-cell-selected" : ""));
        writer.writeIdAttribute(sheetId + "_" + row + "_" + columnIndex);
        final String align = (String) column.getAttributes().get(TobagoConstants.ATTR_ALIGN);
        writer.writeAttribute(HtmlAttributes.STYLE, "top: 0px; left: " + currentLeft + "px; width: "
            + columnWidths.get(columnIndex) + "px; "
            + (align!=null?HtmlRendererUtil.toStyleString("text-align", align):""), false);
        if (column instanceof UIColumnSelector) {
          final boolean disabled = ComponentUtil.getBooleanAttribute(column, TobagoConstants.ATTR_DISABLED);
          writer.startElement(HtmlConstants.IMG, null);
          if (disabled) {
            writer.writeAttribute(HtmlAttributes.SRC, selectorDisabled, false);
          } else {
            writer.writeAttribute(HtmlAttributes.SRC, unchecked, false);
          }
          writer.writeIdAttribute(sheetId + "_data_row_selector_" + row);
          writer.writeClassAttribute("tobago-sheet-column-selector");
          writer.endElement(HtmlConstants.IMG);
        } else {
          List<UIComponent> childs = data.getRenderedChildrenOf(column);
          for (UIComponent grandkid : childs) {
            // set height to 0 to prevent use of layoutheight from parent
            grandkid.getAttributes().put(TobagoConstants.ATTR_LAYOUT_HEIGHT, 0);
            RenderUtil.encode(facesContext, grandkid);
          }
          if (childs.size() > 1) {
            if (LOG.isInfoEnabled()) {
              LOG.info(
                  "Column should not contain more than one child. Please surround the components with a tc:panel.");
            }
          }
        }
        writer.endElement(HtmlConstants.DIV);
        currentLeft += columnWidths.get(columnIndex);
      }

      writer.endElement(HtmlConstants.DIV);
      top += 20;
    }

    data.setRowIndex(-1);

    writer.endElement(HtmlConstants.DIV);

    String image1x1 = contextPath + resourceManager.getImage(viewRoot, "image/1x1.gif");

    int columnCount = 0;
    final int sortMarkerWidth = getAscendingMarkerWidth(facesContext, data);
    String imageAscending = contextPath + resourceManager.getImage(viewRoot, "image/ascending.gif");
    String imageDescending = contextPath + resourceManager.getImage(viewRoot, "image/descending.gif");
    String img = resourceManager.getImage(viewRoot, "image/unsorted.gif", true);
    String imageUnsorted = image1x1;
    if (img != null) {
      imageUnsorted = contextPath + img;
    }
    writer.startElement(HtmlConstants.DIV, null);
    writer.writeIdAttribute(sheetId + "_header_div");
    writer.writeClassAttribute("tobago-simpleSheet-header");
    for (UIColumn column : renderedColumnList) {
      renderColumnHeader(facesContext, writer, data, columnCount, column,
          imageAscending, imageDescending, imageUnsorted, image1x1, sortMarkerWidth, false);
      columnCount++;
    }
    writer.endElement(HtmlConstants.DIV);
    renderFooter(facesContext, data, writer, sheetId, sheetHeight, getFooterHeight(facesContext, data), bodyStyle);

  }
View Full Code Here

      UIComponent component) throws IOException {
    UIPage page = (UIPage) component;

    HtmlRendererUtil.prepareRender(facesContext, page);

    TobagoResponseWriter writer = HtmlRendererUtil.getTobagoResponseWriter(facesContext);

    // replace responseWriter and render page content
    FastStringWriter content = new FastStringWriter(1024*10);
    ResponseWriter contentWriter = writer.cloneWithWriter(content);
    facesContext.setResponseWriter(contentWriter);

    UIComponent menubar = page.getFacet(FACET_MENUBAR);
    if (menubar != null) {
      menubar.getAttributes().put(ATTR_PAGE_MENU, Boolean.TRUE);
      page.getOnloadScripts().add("Tobago.setElementWidth('"
          + menubar.getClientId(facesContext) + "', Tobago.getBrowserInnerWidth())");
      RenderUtil.encode(facesContext, menubar);
    }

    UILayout.getLayout(component).encodeChildrenOfComponent(facesContext, component);
//    RenderUtil.encodeChildren(facesContext, page);

// render popups into buffer
    FastStringWriter popups = new FastStringWriter();
    contentWriter = writer.cloneWithWriter(popups);
    facesContext.setResponseWriter(contentWriter);

    // write popup components
    // beware of ConcurrentModificationException in cascating popups!
    // no foreach
    UIPopup[] popupArray = page.getPopups().toArray(new UIPopup[page.getPopups().size()]);
    for (int i = 0; i < popupArray.length; i++) {
      UIComponent popup = popupArray[i];
      RenderUtil.encode(facesContext, popup);
    }

    // reset responseWriter and render page
    facesContext.setResponseWriter(writer);

    ResponseUtils.ensureNoCacheHeader(facesContext.getExternalContext());

    if (LOG.isDebugEnabled()) {
      for (Object o : page.getAttributes().entrySet()) {
        Map.Entry entry = (Map.Entry) o;
        LOG.debug("*** '" + entry.getKey() + "' -> '" + entry.getValue() + "'");
      }
    }

    Application application = facesContext.getApplication();
    ViewHandler viewHandler = application.getViewHandler();
    String viewId = facesContext.getViewRoot().getViewId();
    String formAction = viewHandler.getActionURL(facesContext, viewId);
    formAction = facesContext.getExternalContext().encodeActionURL(formAction);
    String contentType = writer.getContentTypeWithCharSet();
    ResponseUtils.ensureContentTypeHeader(facesContext, contentType);

    String title = (String) page.getAttributes().get(ATTR_LABEL);

    String doctype = generateDoctype(page);

    if (doctype != null) {
      writer.write(doctype);
      writer.write("\n");
    }

    writer.startElement(HtmlConstants.HTML, null);
    writer.startElement(HtmlConstants.HEAD, null);
    final boolean debugMode =
            ClientProperties.getInstance(facesContext.getViewRoot()).isDebugMode();

    //if (debugMode) {
    writer.writeJavascript("var TbgHeadStart = new Date();");
    //}

    // meta
    // this is needed, because websphere 6.0? ignores the setting of the content type on the response
    writer.startElement(HtmlConstants.META, null);
    writer.writeAttribute("http-equiv", "Content-Type", false);
    writer.writeAttribute("content", contentType, false);
    writer.endElement(HtmlConstants.META);

    // title
    writer.startElement(HtmlConstants.TITLE, null);
    writer.writeText(title != null ? title : "");
    writer.endElement(HtmlConstants.TITLE);

    // style files
    for (String styleFile : page.getStyleFiles()) {
      List<String> styles = ResourceManagerUtil.getStyles(facesContext, styleFile);
      for (String styleString : styles) {
        if (styleString.length() > 0) {
          writer.startElement(HtmlConstants.LINK, null);
          writer.writeAttribute(HtmlAttributes.REL, "stylesheet", false);
          writer.writeAttribute(HtmlAttributes.HREF, styleString, false);
//          writer.writeAttribute(HtmlAttributes.MEDIA, "screen", false);
          writer.writeAttribute(HtmlAttributes.TYPE, "text/css", false);
          writer.endElement(HtmlConstants.LINK);
        }
      }
    }

    String icon = page.getApplicationIcon();
    if (icon != null) {
      // XXX unify with image renderer
      if (ResourceManagerUtil.isAbsoluteResource(icon)) {
        // absolute Path to image : nothing to do
      } else {
        icon = ResourceManagerUtil.getImageWithPath(facesContext, icon);
      }

      writer.startElement(HtmlConstants.LINK, null);
      if (icon.endsWith(".ico")) {
        writer.writeAttribute(HtmlAttributes.REL, "shortcut icon", false);
        writer.writeAttribute(HtmlAttributes.HREF, icon, false);
      } else {
        // XXX IE only supports ICO files for favicons
        writer.writeAttribute(HtmlAttributes.REL, "icon", false);
        writer.writeAttribute(HtmlAttributes.TYPE, MimeTypeUtils.getMimeTypeForFile(icon), false);
        writer.writeAttribute(HtmlAttributes.HREF, icon, false);
      }
      writer.endElement(HtmlConstants.LINK);
    }

    // style sniplets
    Set<String> styleBlocks = page.getStyleBlocks();
    if (styleBlocks.size() > 0) {
      writer.startElement(HtmlConstants.STYLE, null);
      for (String cssBlock : styleBlocks) {
        writer.write(cssBlock);
      }
      writer.endElement(HtmlConstants.STYLE);
    }

    // script files
    List<String> scriptFiles = page.getScriptFiles();
    // prototype.js and tobago.js needs to be first!
    addScripts(writer, facesContext, "script/prototype.js");
    addScripts(writer, facesContext, "script/tobago.js");
    addScripts(writer, facesContext, "script/theme-config.js");
    // remove  prototype.js and tobago.js from list to prevent dublicated rendering of script tags
    scriptFiles.remove("script/prototype.js");
    scriptFiles.remove("script/tobago.js");
    scriptFiles.remove("script/theme-config.js");

    int clientLogSeverity = 2;
    boolean hideClientLogging = true;
    //        true; hideClientLogging = false;
    if (debugMode) {
      String severity = (String) facesContext.getExternalContext().getRequestMap().get(CLIENT_DEBUG_SEVERITY);
      LOG.info("get " + CLIENT_DEBUG_SEVERITY + " = " + severity);
      if (severity != null) {
        try {
          int index = severity.indexOf(';');
          if (index == -1) {
            index = severity.length();
          }
          clientLogSeverity = Integer.parseInt(severity.substring(0, index));
        } catch (NumberFormatException e) {/* ignore; use default*/ }
        hideClientLogging = !severity.contains("show");
      }
      scriptFiles.add("script/effects.js");
      scriptFiles.add("script/dragdrop.js");
      scriptFiles.add("script/logging.js");
    }

    // render remaining script tags
    for (String scriptFile : scriptFiles) {
      addScripts(writer, facesContext, scriptFile);
    }

    // focus id
    String focusId = page.getFocusId();
    if (focusId != null) {
      writer.writeJavascript("Tobago.focusId = '" + focusId + "';");
    }

    if (component.getFacets().containsKey(FACET_ACTION)) {
      UIComponent command = component.getFacet(FACET_ACTION);
      if (command != null && command.isRendered()) {
        int duration = ComponentUtil.getIntAttribute(command, ATTR_DELAY, 100);
        boolean transition = ComponentUtil.getBooleanAttribute(command, ATTR_TRANSITION);
        String target = ComponentUtil.getStringAttribute(command, ATTR_TARGET);
        String action;
        if (target != null) {
          action = "Tobago.submitAction2(this, '" + command.getClientId(facesContext) + "', "
              + transition + ", '" + target + "')";
        } else {
          action = "Tobago.submitAction2(this, '"+ command.getClientId(facesContext) + "', "
              + transition + ", null)";
        }
        page.getOnloadScripts().add("setTimeout(\"" + action  + "\", " + duration + ");\n");
      }
    }

    if (component.getFacets().containsKey(FACET_RESIZE_ACTION)) {
      UIComponent facet = component.getFacet(FACET_RESIZE_ACTION);
      UIComponent command = null;
      if (facet instanceof UICommand) {
        command = facet;
      } else if (facet instanceof UIForm && facet.getChildCount() == 1) {
        command = (UIComponent) facet.getChildren().get(0);
      }
      if (command != null && command.isRendered()) {
        writer.writeJavascript("Tobago.resizeActionId = '" + command.getClientId(facesContext) + "';");
      }
    }

    StringBuilder script = new StringBuilder(128);

    // onload script
    writeEventFunction(script, page.getOnloadScripts(), "load", false);

    // onunload script
    writeEventFunction(script, page.getOnunloadScripts(), "unload", false);

    // onexit script
    writeEventFunction(script, page.getOnexitScripts(), "exit", false);

    writeEventFunction(script, page.getOnsubmitScripts(), "submit", true);

   int debugCounter = 0;
    for (String scriptBlock : page.getScriptBlocks()) {

      if (LOG.isDebugEnabled()) {
        LOG.debug("write scriptblock " + ++debugCounter + " :\n" + scriptBlock);
      }
      script.append(scriptBlock);
      script.append('\n');
    }
    writer.writeJavascript(script.toString());

    String clientId = page.getClientId(facesContext);

    String defaultActionId = page.getDefaultActionId() != null ? page.getDefaultActionId() : "";
    writer.endElement(HtmlConstants.HEAD);
    writer.startElement(HtmlConstants.BODY, page);
    writer.writeAttribute(HtmlAttributes.ONLOAD, "Tobago.init('" + clientId + "');", false);
//    writer.writeAttribute("onunload", "Tobago.onexit();", null);
    //this ist for ie to prevent scrollbars where none are needed
    writer.writeAttribute(HtmlAttributes.SCROLL, "auto", false);
    writer.writeClassAttribute();
    writer.writeIdAttribute(clientId);

    StringBuilder images = new StringBuilder(256);
    images.append("Tobago.pngFixBlankImage = '");
    images.append(ResourceManagerUtil.getImageWithPath(facesContext, "image/blank.gif"));
    images.append("';\n");
    images.append("Tobago.OVERLAY_BACKGROUND = '");
    images.append(ResourceManagerUtil.getImageWithPath(facesContext, "image/tobago-overlay-background.png"));
    images.append("';\n");
    images.append("Tobago.OVERLAY_WAIT = '");
    images.append(ResourceManagerUtil.getImageWithPath(facesContext, "image/tobago-overlay-wait.gif"));
    images.append("';\n");
    writer.writeJavascript(images.toString());

    if (debugMode) {
      final String[] jsFiles = new String[]{
          "script/effects.js",
          "script/dragdrop.js",
          "script/logging.js"
      };
      final String[] jsCommand = new String[]{"new LOG.LogArea({hide: " + hideClientLogging + "});"};
      HtmlRendererUtil.writeScriptLoader(facesContext, jsFiles, jsCommand);
    }
    //if (debugMode)  {
    writer.writeJavascript("TbgTimer.startBody = new Date();");
    //}

    writer.startElement(HtmlConstants.FORM, page);
    writer.writeNameAttribute(
        clientId + SUBCOMPONENT_SEP + "form");
    writer.writeAttribute(HtmlAttributes.ACTION, formAction, true);
    writer.writeIdAttribute(page.getFormId(facesContext));
    writer.writeAttribute(HtmlAttributes.METHOD, getMethod(page), false);
    String enctype = (String) facesContext.getExternalContext().getRequestMap().get(UIPage.ENCTYPE_KEY);
    if (enctype != null) {
      writer.writeAttribute(HtmlAttributes.ENCTYPE, enctype, false);
    } else {
      writer.writeAttributeFromComponent(HtmlAttributes.ENCTYPE, ATTR_ENCTYPE);
    }
    // TODO: enable configuration of  'accept-charset'
    writer.writeAttribute(HtmlAttributes.ACCEPT_CHARSET, FORM_ACCEPT_CHARSET, false);

    writer.startElement(HtmlConstants.INPUT, null);
    writer.writeAttribute(HtmlAttributes.TYPE, "hidden", false);
    writer.writeNameAttribute(clientId + SUBCOMPONENT_SEP + "form-action");
    writer.writeIdAttribute(clientId + SUBCOMPONENT_SEP + "form-action");
    writer.writeAttribute(HtmlAttributes.VALUE, defaultActionId, true);
    writer.endElement(HtmlConstants.INPUT);

    writer.startElement(HtmlConstants.INPUT, null);
    writer.writeAttribute(HtmlAttributes.TYPE, "hidden", false);
    writer.writeNameAttribute(clientId + SUBCOMPONENT_SEP + "context-path");
    writer.writeIdAttribute(clientId + SUBCOMPONENT_SEP + "context-path");
    writer.writeAttribute(HtmlAttributes.VALUE, facesContext.getExternalContext().getRequestContextPath(), true);
    writer.endElement(HtmlConstants.INPUT);

    writer.startElement(HtmlConstants.INPUT, null);
    writer.writeAttribute(HtmlAttributes.TYPE, "hidden", false);
    writer.writeNameAttribute(clientId + SUBCOMPONENT_SEP + "action-position");
    writer.writeIdAttribute(clientId + SUBCOMPONENT_SEP + "action-position");
    writer.endElement(HtmlConstants.INPUT);

    if (debugMode) {
      writer.startElement(HtmlConstants.INPUT, null);
      writer.writeAttribute(HtmlAttributes.VALUE, clientLogSeverity);
      writer.writeAttribute(HtmlAttributes.ID, clientId + SUBCOMPONENT_SEP + "clientSeverity", false);
      writer.writeAttribute(HtmlAttributes.NAME, clientId + SUBCOMPONENT_SEP + "clientSeverity", false);
      writer.writeAttribute(HtmlAttributes.TYPE, "hidden", false);
      writer.endElement(HtmlConstants.INPUT);
    }

    if (component.getFacet("backButtonDetector") != null) {
      UIComponent hidden = component.getFacet("backButtonDetector");
      RenderUtil.encode(facesContext, hidden);
    }
    String lastFocusId = (String) component.getAttributes().get(LAST_FOCUS_ID);
    if (lastFocusId != null) {
      writer.writeJavascript("Tobago.lastFocusId = '" + lastFocusId + "';");
      component.getAttributes().remove(LAST_FOCUS_ID);
    }
    //checkForCommandFacet(component, facesContext, writer);

// TODO: this is needed for the "BACK-BUTTON-PROBLEM"
// but may no longer needed
/*
    if (ViewHandlerImpl.USE_VIEW_MAP) {
      writer.startElement(HtmlConstants.INPUT, null);
      writer.writeAttribute(HtmlAttributes.TYPE, "hidden", null);
      writer.writeNameAttribute(ViewHandlerImpl.PAGE_ID);
      writer.writeIdAttribute(ViewHandlerImpl.PAGE_ID);
      Object value = facesContext.getViewRoot().getAttributes().get(
          ViewHandlerImpl.PAGE_ID);
      writer.writeAttribute(HtmlAttributes.VALUE, (value != null ? value : ""), null);
      writer.endElement(HtmlConstants.INPUT);
    }
*/

    // write the proviously rendered page content
    writer.write(content.toString());

    // write the previously rendered popups
    writer.write(popups.toString());

    writer.startElement(HtmlConstants.SPAN, null);
    writer.writeIdAttribute(clientId + SUBCOMPONENT_SEP + "jsf-state-container");
    writer.flush();

    // catch the next written stuff into a string and look if it is empty (TOBAGO-909)
    FastStringWriter buffer = new FastStringWriter(40); // usually only the marker...
    TobagoResponseWriter originalWriter = (TobagoResponseWriter) facesContext.getResponseWriter();
    writer = (TobagoResponseWriter) writer.cloneWithWriter(buffer);
    facesContext.setResponseWriter(writer);
    viewHandler.writeState(facesContext);
    final String stateContent = buffer.toString();
    writer = originalWriter;
View Full Code Here

    if (TobagoConfig.getInstance(facesContext).isAjaxEnabled()) {
      HtmlRendererUtil.writeScriptLoader(facesContext, SCRIPTS, new String[0]);
    }

    TobagoResponseWriter writer = HtmlRendererUtil.getTobagoResponseWriter(facesContext);
    writer.startElement(HtmlConstants.INPUT, null);
    writer.writeAttribute(HtmlAttributes.TYPE, "hidden", false);
    writer.writeAttribute(HtmlAttributes.VALUE, Integer.toString(activeIndex), false);
    writer.writeNameAttribute(hiddenId);
    writer.writeIdAttribute(hiddenId);
    writer.endElement(HtmlConstants.INPUT);

    String image1x1 = ResourceManagerUtil.getImageWithPath(facesContext, "image/1x1.gif");

    TabList tabList = getTabList(facesContext, component);

    // if a outer uiPage is presend, the virtual tab will go over all
    // tabs and render it as they are selected, and it will
    // selected with stylesheet.
    int virtualTab = 0;
    int currentWidth = 0;
    int navigationBarWidth = 0;
    if (ComponentUtil.getBooleanAttribute(component, TobagoConstants.ATTR_SHOW_NAVIGATION_BAR)) {
      navigationBarWidth = getConfiguredValue(facesContext, component, "navigationBarWidth");
    }
    for (UIComponent tab : (List<UIComponent>) component.getChildren()) {
      if (tab instanceof UIPanelBase) {
        if (tab.isRendered()) {
          currentWidth += tabList.getWidthList().get(virtualTab);
          if (SWITCH_TYPE_CLIENT.equals(switchType) || virtualTab == activeIndex) {

            if (virtualTab != activeIndex) {
              HtmlRendererUtil.replaceStyleAttribute(component, "display", "none");
            } else {
              HtmlRendererUtil.removeStyleAttribute(component, "display");
            }

            writer.startElement(HtmlConstants.DIV, null);
            writer.writeComment("empty div fix problem with mozilla and fieldset");
            writer.endElement(HtmlConstants.DIV);

            writer.startElement(HtmlConstants.DIV, null);
            writer.writeIdAttribute(clientId);
            StyleClasses classes = (StyleClasses) component.getAttributes().get(ATTR_STYLE_CLASS);
            writer.writeClassAttribute(classes);
            renderTabGroupView(facesContext, writer, component, virtualTab,
                (HtmlStyleMap) component.getAttributes().get(ATTR_STYLE),
                switchType, image1x1, navigationBarWidth, currentWidth, tabList);
            writer.endElement(HtmlConstants.DIV);

            if (TobagoConfig.getInstance(facesContext).isAjaxEnabled()
                && SWITCH_TYPE_RELOAD_TAB.equals(switchType)) {
              final String[] cmds = {
                  "new Tobago.TabGroup(",
View Full Code Here

    if (ComponentUtil.getBooleanAttribute(component, ATTR_MENU_POPUP)) {
      clientId = component.getParent().getClientId(facesContext);
    } else {
      clientId = component.getClientId(facesContext);
      TobagoResponseWriter writer = HtmlRendererUtil.getTobagoResponseWriter(facesContext);

      writer.startElement(HtmlConstants.DIV, component);
      writer.writeIdAttribute(clientId);
      StyleClasses styleClasses = StyleClasses.ensureStyleClasses(component);
      if (ComponentUtil.getBooleanAttribute(component, ATTR_PAGE_MENU)) {
        styleClasses.addClass("menuBar", "page-facet"); // XXX not a standard compliant name
      } else {
        writer.writeStyleAttribute();
      }
      writer.writeClassAttribute(styleClasses);
/*

      writer.startElement(HtmlConstants.SPAN);
      writer.writeAttribute(HtmlAttributes.STYLE, "position: relative", null);
//      writer.writeClassAttribute("tobago-menuBar-container");

      renderTopLevelItems(facesContext, writer, component);

      writer.endElement(HtmlConstants.SPAN);

*/
      writer.endElement(HtmlConstants.DIV);
    }
    List<String> accKeyFunctions = new ArrayList<String>();
    StringBuilder scriptBuffer = new StringBuilder();
    String setupFunction
        = createSetupFunction(facesContext, component, clientId, accKeyFunctions, scriptBuffer);
View Full Code Here

      throws IOException {
    ResponseWriter savedWriter = facesContext.getResponseWriter();
    FastStringWriter stringWriter = new FastStringWriter();
    ResponseWriter newWriter = savedWriter.cloneWithWriter(stringWriter);
    facesContext.setResponseWriter(newWriter);
    TobagoResponseWriter writer = HtmlRendererUtil.getTobagoResponseWriter(facesContext);

    writeMenuEntry(facesContext, writer, accKeyFunctions, uiPanel);

    facesContext.setResponseWriter(savedWriter);
View Full Code Here

    ResponseWriter savedWriter = facesContext.getResponseWriter();
    FastStringWriter stringWriter = new FastStringWriter();
    ResponseWriter newWriter = savedWriter.cloneWithWriter(stringWriter);
    facesContext.setResponseWriter(newWriter);
    TobagoResponseWriter writer = HtmlRendererUtil.getTobagoResponseWriter(facesContext);
    addImage(writer, facesContext, image, disabled);

    writer.startElement(HtmlConstants.A, null);
    writer.writeClassAttribute(spanClass);
    writer.writeIdAttribute(command.getClientId(facesContext));
    if (label.getAccessKey() != null) {
      if (LOG.isInfoEnabled()
          && !AccessKeyMap.addAccessKey(facesContext, label.getAccessKey())) {
        LOG.info("duplicate accessKey : " + label.getAccessKey() + " in " + label.getText());
      }

      if (!disabled) {
        addAcceleratorKey(facesContext, accKeyFunctions, command, label.getAccessKey());
      }
    }
    writer.writeAttribute(HtmlAttributes.HREF, "#", false);
    writer.writeAttribute(HtmlAttributes.ONFOCUS, "tobagoMenuFocus(event)", false);
    writer.writeAttribute(HtmlAttributes.ONBLUR, "tobagoMenuBlur(event)", false);
    writer.writeAttribute(HtmlAttributes.ONKEYDOWN, "tobagoMenuKeyDown(event)", false);
    writer.writeAttribute(HtmlAttributes.ONKEYPRESS, "tobagoMenuKeyPress(event)", false);
    if (label.getText() != null) {
      HtmlRendererUtil.writeLabelWithAccessKey(writer, label);
    }
    writer.endElement(HtmlConstants.A);

    facesContext.setResponseWriter(savedWriter);
    final String html = stringWriter.toString();

    sb.append("    ");
View Full Code Here

    if (LOG.isDebugEnabled()) {
      LOG.debug("items.size() = '" + items.size() + "'");
    }

    TobagoResponseWriter writer = HtmlRendererUtil.getTobagoResponseWriter(facesContext);
    String title = HtmlRendererUtil.getTitleFromTipAndMessages(facesContext, selectMany);
    writer.startElement(HtmlConstants.SELECT, selectMany);
    String clientId = selectMany.getClientId(facesContext);
    writer.writeNameAttribute(clientId);
    writer.writeIdAttribute(clientId);
    boolean renderDisabled = ComponentUtil.getBooleanAttribute(selectMany, ATTR_DISABLED)
        || ComponentUtil.getBooleanAttribute(selectMany, ATTR_READONLY);
    writer.writeAttribute(HtmlAttributes.DISABLED, renderDisabled);
    Integer tabIndex = selectMany.getTabIndex();
    if (tabIndex != null) {
      writer.writeAttribute(HtmlAttributes.TABINDEX, tabIndex);
    }
    writer.writeStyleAttribute();
    writer.writeClassAttribute();
    writer.writeAttribute(HtmlAttributes.MULTIPLE, HtmlAttributes.MULTIPLE, false);
    if (title != null) {
      writer.writeAttribute(HtmlAttributes.TITLE, title, true);
    }
    Object[] values = selectMany.getSelectedValues();
    if (LOG.isDebugEnabled()) {
      LOG.debug("values = '" + Arrays.toString(values) + "'");
    }
    HtmlRendererUtil.renderSelectItems(selectMany, items, values, writer, facesContext);

    writer.endElement(HtmlConstants.SELECT);
    checkForCommandFacet(selectMany, facesContext, writer);
  }
View Full Code Here

      String id = component.getClientId(facesContext);
      if (!StringUtils.isBlank(page.getFocusId()) && !page.getFocusId().equals(id)) {
        LOG.warn("page focusId = \"" + page.getFocusId() + "\" ignoring new value \""
            + id + "\"");
      } else {
        TobagoResponseWriter writer = HtmlRendererUtil.getTobagoResponseWriter(facesContext);
        writer.writeJavascript("Tobago.focusId = '" + id + "';");
      }
    }
  }
View Full Code Here

    writeScriptLoader(facesContext, new String[]{script}, null);
  }

  public static void writeScriptLoader(FacesContext facesContext, String[] scripts, String[] afterLoadCmds)
      throws IOException {
    TobagoResponseWriter writer = HtmlRendererUtil.getTobagoResponseWriter(facesContext);

    String allScripts = "[]";
    if (scripts != null) {
      allScripts = ResourceManagerUtil.getScriptsAsJSArray(facesContext, scripts);
    }

    StringBuilder script = new StringBuilder();
    script.append("new Tobago.ScriptLoader(\n    ");
    script.append(allScripts);

    if (afterLoadCmds != null && afterLoadCmds.length > 0) {
      script.append(", \n");
      boolean first = true;
      for (String afterLoadCmd : afterLoadCmds) {
        String[] splittedStrings = StringUtils.split(afterLoadCmd, '\n'); // split on <CR> to have nicer JS
        for (String splitted : splittedStrings) {
          String cmd = StringUtils.replace(splitted, "\\", "\\\\");
          cmd = StringUtils.replace(cmd, "\"", "\\\"");
          script.append(first ? "          " : "        + ");
          script.append("\"");
          script.append(cmd);
          script.append("\"\n");
          first = false;
        }
      }
    }
    script.append(");");

    writer.writeJavascript(script.toString());
  }
View Full Code Here

TOP

Related Classes of org.apache.myfaces.tobago.webapp.TobagoResponseWriter

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.