Examples of TobagoFacesContext


Examples of org.apache.myfaces.tobago.context.TobagoFacesContext

    renderExecutor = new RenderResponseExecutor();
  }

  public void execute(FacesContext facesContext) throws FacesException {

    TobagoFacesContext context = new TobagoFacesContext(facesContext);
    PhaseListenerManager phaseListenerMgr = new PhaseListenerManager(this, context, getPhaseListeners());

    // At very first ensure the requestEncoding, this MUST done before
    // accessing request parameters, wich can occur in custom phaseListeners.
    RequestUtils.ensureEncoding(context);
View Full Code Here

Examples of org.apache.myfaces.tobago.context.TobagoFacesContext

  }

  public void render(FacesContext facesContext) throws FacesException {
    // if the response is complete we should not be invoking the phase listeners
    if (!(facesContext instanceof TobagoFacesContext)) {
      facesContext = new TobagoFacesContext(facesContext);
    }

    if (isResponseComplete(facesContext, renderExecutor.getPhase(), true)) {
      return;
    }
View Full Code Here

Examples of org.apache.myfaces.tobago.context.TobagoFacesContext

  public void encodeBegin(FacesContext facesContextOrg, UIComponent component) throws IOException {

    UIPage page = (UIPage) component;

    // invoke prepareRender
    TobagoFacesContext facesContext;
    if (facesContextOrg instanceof TobagoFacesContext) {
      facesContext = (TobagoFacesContext) facesContextOrg;
    } else {
      facesContext = new TobagoFacesContext(facesContextOrg);
    }

    RenderUtils.prepareRendererAll(facesContext, page);

    LayoutContext layoutContext = new LayoutContext(page);
    layoutContext.layout();

    TobagoResponseWriter writer = HtmlRendererUtils.getTobagoResponseWriter(facesContext);

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

    ResponseUtils.ensureNoCacheHeader(facesContext);

    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 clientId = page.getClientId(facesContext);
    final ClientProperties client = VariableResolverUtils.resolveClientProperties(facesContext);
    final ProjectStage projectStage = TobagoConfig.getInstance(facesContext).getProjectStage();
    final boolean developmentMode =  projectStage == ProjectStage.Development;
    final boolean debugMode = client.isDebugMode() || developmentMode;
    final boolean productionMode = !debugMode && projectStage == ProjectStage.Production;
    boolean calculateScrollbarWeight = false;
    int clientLogSeverity = 2;
    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*/ }
      }
    }

    if (!facesContext.isAjax()) {
      HtmlRendererUtils.renderDojoDndSource(facesContext, component);

      String title = (String) page.getAttributes().get(Attributes.LABEL);

      writer.startElement(HtmlElements.HEAD, null);

      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(HtmlElements.META, null);
      writer.writeAttribute(HtmlAttributes.HTTP_EQUIV, "Content-Type", false);
      writer.writeAttribute(HtmlAttributes.CONTENT, contentType, false);
      writer.endElement(HtmlElements.META);

      // title
      writer.startElement(HtmlElements.TITLE, null);
      writer.writeText(title != null ? title : "");
      writer.endElement(HtmlElements.TITLE);
      final Theme theme = client.getTheme();

      // style files
      for (String styleFile : theme.getStyleResources(productionMode)) {
        writeStyle(facesContext, writer, styleFile);
      }

      for (String styleFile : facesContext.getStyleFiles()) {
        writeStyle(facesContext, writer, styleFile);
      }

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

        writer.startElement(HtmlElements.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(HtmlElements.LINK);
      }

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

      if (debugMode) {
        boolean hideClientLogging = true;
        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");
        }
        // the jquery ui is used in moment only for the logging area...
        facesContext.getOnloadScripts().add(0, "new LOG.LogArea({hide: " + hideClientLogging + "});");
      }

      // render remaining script tags
      for (String scriptFile: theme.getScriptResources(productionMode)) {
        encodeScript(facesContext, writer, scriptFile);
      }

      for (String scriptFile : facesContext.getScriptFiles()) {
        encodeScript(facesContext, writer, scriptFile);
      }

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

      if (component.getFacets().containsKey(Facets.ACTION)) {
        UIComponent command = component.getFacet(Facets.ACTION);
        if (command != null && command.isRendered()) {
          int duration = ComponentUtils.getIntAttribute(command, Attributes.DELAY, 100);
          boolean transition = ComponentUtils.getBooleanAttribute(command, Attributes.TRANSITION);
          String target = ComponentUtils.getStringAttribute(command, Attributes.TARGET);
          String action;
          if (target != null) {
            action = "Tobago.submitAction(this, '" + command.getClientId(facesContext) + "', "
                    + transition + ", '" + target + "' )";
          } else {
            action = "Tobago.submitAction(this, '"+ command.getClientId(facesContext) + "', " + transition + " )";
          }
          facesContext.getOnloadScripts().add("setTimeout(\"" + action  + "\", " + duration + ");\n");
        }
      }


      calculateScrollbarWeight
          = client.getVerticalScrollbarWeight() == null || client.getHorizontalScrollbarWeight() == null;
      if (calculateScrollbarWeight) {
        facesContext.getOnloadScripts().add(
            "Tobago.calculateScrollbarWeights('" + clientId + ComponentUtils.SUB_SEPARATOR + "scrollbarWeight" + "');");
      } else {
        facesContext.getOnloadScripts().add(
            "Tobago.Config.set('Tobago', 'verticalScrollbarWeight', '"
                + client.getVerticalScrollbarWeight().getPixel() + "');");
        facesContext.getOnloadScripts().add(
            "Tobago.Config.set('Tobago', 'horizontalScrollbarWeight', '"
                + client.getHorizontalScrollbarWeight().getPixel() + "');");
      }

      if (component.getFacets().containsKey(Facets.RESIZE_ACTION)) {
        UIComponent facet = component.getFacet(Facets.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) + "';");
        }
      }

      writer.startJavascript();
      // onload script
      writeEventFunction(writer, facesContext.getOnloadScripts(), "load", false);

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

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

      writeEventFunction(writer, facesContext.getOnsubmitScripts(), "submit", true);

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

        if (LOG.isDebugEnabled()) {
          LOG.debug("write scriptblock " + ++debugCounter + " :\n" + scriptBlock);
        }
        writer.write(scriptBlock);
        writer.write('\n');
      }
      writer.endJavascript();
      writer.endElement(HtmlElements.HEAD);
    }

    String defaultActionId = page.getDefaultActionId() != null ? page.getDefaultActionId() : "";
    writer.startElement(HtmlElements.BODY, page);
    writer.writeAttribute(HtmlAttributes.ONLOAD, "Tobago.init('" + clientId + "');", false);
//    writer.writeAttribute("onunload", "Tobago.onexit();", null);
    writer.writeIdAttribute(clientId);
    writer.writeClassAttribute(Classes.create(page));

    writer.startJavascript();
    writer.write("Tobago.pngFixBlankImage = '");
    writer.write(ResourceManagerUtils.getImageWithPath(facesContext, "image/blank.gif"));
    writer.write("';\n");
    writer.write("Tobago.OVERLAY_BACKGROUND = '");
    writer.write(ResourceManagerUtils.getImageWithPath(facesContext, "image/tobago-overlay-background.png"));
    writer.write("';\n");
    writer.write("Tobago.OVERLAY_WAIT = '");
    writer.write(ResourceManagerUtils.getImageWithPath(facesContext, "image/tobago-overlay-wait.gif"));
    writer.write("';\n");
    writer.endJavascript();
/*
    if (debugMode) {
      final String[] jsFiles = new String[]{
          "script/logging.js"
      };
      final String[] jsCommand = new String[]{"new LOG.LogArea({hide: " + hideClientLogging + "});"};
      HtmlRendererUtils.writeScriptLoader(facesContext, jsFiles, jsCommand);
      writer.writeJavascript("TbgTimer.startBody = new Date();");
    }
*/
    if (debugMode) {
      writer.writeJavascript("TbgTimer.startBody = new Date();");
    }

    writer.startElement(HtmlElements.FORM, page);
    writer.writeAttribute(HtmlAttributes.ACTION, formAction, true);
    writer.writeIdAttribute(page.getFormId(facesContext));
    writer.writeAttribute(HtmlAttributes.METHOD, getMethod(page), false);
    String enctype = facesContext.getEnctype();
    if (enctype != null) {
      writer.writeAttribute(HtmlAttributes.ENCTYPE, enctype, false);
    }
    // TODO: enable configuration of  'accept-charset'
    writer.writeAttribute(HtmlAttributes.ACCEPT_CHARSET, AbstractUIPage.FORM_ACCEPT_CHARSET, false);

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

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

    writer.startElement(HtmlElements.INPUT, null);
    writer.writeAttribute(HtmlAttributes.TYPE, "hidden", false);
    writer.writeNameAttribute(clientId + ComponentUtils.SUB_SEPARATOR + "action-position");
View Full Code Here

Examples of org.apache.myfaces.tobago.context.TobagoFacesContext

//  }

  @Override
  public void encodeEnd(FacesContext facesContextOrg, UIComponent component) throws IOException {

    TobagoFacesContext facesContext;
    if (facesContextOrg instanceof TobagoFacesContext) {
      facesContext = (TobagoFacesContext) facesContextOrg;
    } else {
      facesContext = new TobagoFacesContext(facesContextOrg);
    }

    UIPage page = (UIPage) component;
    TobagoResponseWriter writer = HtmlRendererUtils.getTobagoResponseWriter(facesContext);

    writer.endElement(HtmlElements.DIV);

    // write popup components
    // beware of ConcurrentModificationException in cascading popups!
    // no foreach
    UIPopup[] popupArray = facesContext.getPopups().toArray(new UIPopup[facesContext.getPopups().size()]);
    for (UIPopup popup : popupArray) {
      RenderUtils.encode(facesContext, popup);
    }

    String clientId = page.getClientId(facesContext);
    final boolean debugMode = VariableResolverUtils.resolveClientProperties(facesContext).isDebugMode();

    Application application = facesContext.getApplication();
    ViewHandler viewHandler = application.getViewHandler();

    writer.startElement(HtmlElements.SPAN, null);
    writer.writeIdAttribute(clientId + ComponentUtils.SUB_SEPARATOR + "jsf-state-container");
    writer.flush();
    if (!facesContext.isAjax()) {
      if (FacesVersion.supports12()) {
        viewHandler.writeState(facesContext);
      } else {
        // 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;
        facesContext.setResponseWriter(writer);

        if (StringUtils.isBlank(stateContent)) {
          if (LOG.isDebugEnabled()) {
            LOG.debug("Writing state will not happen! So we write the hidden field manually.");
          }
          writer.startElement(HtmlElements.INPUT, null);
          writer.writeAttribute(HtmlAttributes.TYPE, "hidden", false);
          writer.writeAttribute(HtmlAttributes.NAME, TobagoResponseStateManager.TREE_PARAM, false);
          writer.writeAttribute(HtmlAttributes.ID, TobagoResponseStateManager.TREE_PARAM, false);
          writer.writeAttribute(HtmlAttributes.VALUE, "workaround", false);
          writer.endElement(HtmlElements.INPUT);
        } else {
          writer.write(stateContent);
        }
      }
    }
    writer.endElement(HtmlElements.SPAN);

    // avoid submit page in ie if the form contains only one input and you press the enter key in the input
    if (VariableResolverUtils.resolveClientProperties(facesContext).getUserAgent().isMsie()) {
      writer.startElement(HtmlElements.INPUT, null);
      writer.writeAttribute(HtmlAttributes.TYPE, HtmlInputTypes.TEXT, false);
      writer.writeAttribute(HtmlAttributes.NAME, "tobago.dummy", false);
      writer.writeAttribute(HtmlAttributes.TABINDEX, "-1", false);
      writer.writeAttribute(HtmlAttributes.STYLE, "visibility:hidden;display:none;", false);
      writer.endElement(HtmlElements.INPUT);
    }

    List<String> messageClientIds = AjaxInternalUtils.getMessagesClientIds(facesContext);
    if (messageClientIds != null) {
      writer.startElement(HtmlElements.INPUT, null);
      writer.writeAttribute(HtmlAttributes.VALUE, StringUtils.join(messageClientIds, ','), true);
      writer.writeAttribute(HtmlAttributes.ID, clientId + ComponentUtils.SUB_SEPARATOR + "messagesClientIds", false);
      writer.writeAttribute(HtmlAttributes.NAME, clientId + ComponentUtils.SUB_SEPARATOR + "messagesClientIds", false);
      writer.writeAttribute(HtmlAttributes.TYPE, "hidden", false);
      writer.endElement(HtmlElements.INPUT);
    }

    // placeholder for menus
    writer.startElement(HtmlElements.DIV, page);
    writer.writeClassAttribute(Classes.create(page, "menuStore"));
    writer.endElement(HtmlElements.DIV);
   
    writer.endElement(HtmlElements.FORM);

    // debugging...
    if (debugMode) {
      List<String> logMessages = new ArrayList<String>();
      for (Iterator ids = facesContext.getClientIdsWithMessages();
           ids.hasNext();) {
        String id = (String) ids.next();
        for (Iterator messages = facesContext.getMessages(id);
             messages.hasNext();) {
          FacesMessage message = (FacesMessage) messages.next();
          logMessages.add(errorMessageForDebugging(id, message));
        }
       
      }
      if (!logMessages.isEmpty()) {
        logMessages.add(0, "LOG.show();");
      }

      logMessages.add("LOG.info(\"FacesContext = " + facesContext + "\");");

      HtmlRendererUtils.writeScriptLoader(facesContext, null,
          logMessages.toArray(new String[logMessages.size()]));
    }

    if (debugMode) {
      writer.writeJavascript("TbgTimer.endBody = new Date();");
    }

    writer.writeJavascript("setTimeout(\"Tobago.init('" + clientId + "')\", 1000)");

    writer.endElement(HtmlElements.BODY);

    if (LOG.isDebugEnabled()) {
      LOG.debug("unused AccessKeys    : "
          + AccessKeyMap.getUnusedKeys(facesContext));
      LOG.debug("duplicated AccessKeys: "
          + AccessKeyMap.getDublicatedKeys(facesContext));
    }

    if (facesContext.getExternalContext().getRequestParameterMap().get("X") != null) {
      throw new RuntimeException("Debugging activated via X parameter");
    }
  }
View Full Code Here

Examples of org.apache.myfaces.tobago.context.TobagoFacesContext

    if (facesContext instanceof TobagoFacesContext) {
      ((TobagoFacesContext) facesContext).getPopups().add(popup);
    }

    // TODO: where to put this code, it is good here?
    TobagoFacesContext tobagoContext = (TobagoFacesContext) facesContext;
    tobagoContext.getScriptBlocks().add("jQuery(document).ready(function() {Tobago.setupPopup();});");

    super.prepareRender(facesContext, popup);

    if (popup.isModal()) {
      popup.setCurrentMarkup(popup.getCurrentMarkup().add(Markup.MODAL));
View Full Code Here

Examples of org.apache.myfaces.tobago.context.TobagoFacesContext

    renderExecutor = new RenderResponseExecutor();
  }

  public void execute(FacesContext facesContext) throws FacesException {

    TobagoFacesContext context = new TobagoFacesContext(facesContext);
    PhaseListenerManager phaseListenerMgr = new PhaseListenerManager(this, context, getPhaseListeners());

    // At very first ensure the requestEncoding, this MUST done before
    // accessing request parameters, wich can occur in custom phaseListeners.
    RequestUtils.ensureEncoding(context);
View Full Code Here

Examples of org.apache.myfaces.tobago.context.TobagoFacesContext

    return skipFurtherProcessing;
  }

  public void render(FacesContext facesContext) throws FacesException {
    if (!(facesContext instanceof TobagoFacesContext)) {
      facesContext = new TobagoFacesContext(facesContext);
    }
    // if the response is complete we should not be invoking the phase listeners
    if (isResponseComplete(facesContext, renderExecutor.getPhase(), true)) {
      return;
    }
View Full Code Here

Examples of org.apache.myfaces.tobago.context.TobagoFacesContext

    if (facesContext instanceof TobagoFacesContext) {
      ((TobagoFacesContext) facesContext).getPopups().add(popup);
    }

    // TODO: where to put this code, it is good here?
    TobagoFacesContext tobagoContext = (TobagoFacesContext) facesContext;
    tobagoContext.getScriptBlocks().add("jQuery(document).ready(function() {Tobago.setupPopup();});");

    super.prepareRender(facesContext, popup);

    if (popup.isModal()) {
      popup.setCurrentMarkup(popup.getCurrentMarkup().add(Markup.MODAL));
View Full Code Here

Examples of org.apache.myfaces.tobago.context.TobagoFacesContext

  public void encodeBegin(FacesContext facesContextOrg, UIComponent component) throws IOException {

    UIPage page = (UIPage) component;

    // invoke prepareRender
    TobagoFacesContext facesContext;
    if (facesContextOrg instanceof TobagoFacesContext) {
      facesContext = (TobagoFacesContext) facesContextOrg;
    } else {
      facesContext = new TobagoFacesContext(facesContextOrg);
    }

    RenderUtils.prepareRendererAll(facesContext, page);

    LayoutContext layoutContext = new LayoutContext(page);
    layoutContext.layout();

    TobagoResponseWriter writer = HtmlRendererUtils.getTobagoResponseWriter(facesContext);

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

    ResponseUtils.ensureNoCacheHeader(facesContext);

    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 clientId = page.getClientId(facesContext);
    final ClientProperties client = VariableResolverUtils.resolveClientProperties(facesContext);
    final ProjectStage projectStage = TobagoConfig.getInstance(facesContext).getProjectStage();
    final boolean developmentMode =  projectStage == ProjectStage.Development;
    final boolean debugMode = client.isDebugMode() || developmentMode;
    final boolean productionMode = !debugMode && projectStage == ProjectStage.Production;
    boolean calculateScrollbarWeight = false;
    int clientLogSeverity = 2;
    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*/ }
      }
    }

    if (!facesContext.isAjax()) {
      HtmlRendererUtils.renderDojoDndSource(facesContext, component);

      String title = (String) page.getAttributes().get(Attributes.LABEL);

      writer.startElement(HtmlElements.HEAD, null);

      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(HtmlElements.META, null);
      writer.writeAttribute(HtmlAttributes.HTTP_EQUIV, "Content-Type", false);
      writer.writeAttribute(HtmlAttributes.CONTENT, contentType, false);
      writer.endElement(HtmlElements.META);

      // title
      writer.startElement(HtmlElements.TITLE, null);
      writer.writeText(title != null ? title : "");
      writer.endElement(HtmlElements.TITLE);
      final Theme theme = client.getTheme();

      // style files
      for (String styleFile : theme.getStyleResources(productionMode)) {
        writeStyle(facesContext, writer, styleFile);
      }

      for (String styleFile : facesContext.getStyleFiles()) {
        writeStyle(facesContext, writer, styleFile);
      }

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

        writer.startElement(HtmlElements.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(HtmlElements.LINK);
      }

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

      if (debugMode) {
        boolean hideClientLogging = true;
        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");
        }
        // the jquery ui is used in moment only for the logging area...
        facesContext.getOnloadScripts().add(0, "new LOG.LogArea({hide: " + hideClientLogging + "});");
      }

      // render remaining script tags
      for (String scriptFile: theme.getScriptResources(productionMode)) {
        encodeScript(facesContext, writer, scriptFile);
      }

      for (String scriptFile : facesContext.getScriptFiles()) {
        encodeScript(facesContext, writer, scriptFile);
      }

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

      if (component.getFacets().containsKey(Facets.ACTION)) {
        UIComponent command = component.getFacet(Facets.ACTION);
        if (command != null && command.isRendered()) {
          int duration = ComponentUtils.getIntAttribute(command, Attributes.DELAY, 100);
          boolean transition = ComponentUtils.getBooleanAttribute(command, Attributes.TRANSITION);
          String target = ComponentUtils.getStringAttribute(command, Attributes.TARGET);
          String action
              = HtmlRendererUtils.createSubmitAction(command.getClientId(facesContext), transition, target, null);
          facesContext.getOnloadScripts().add("setTimeout(\"" + action  + "\", " + duration + ");\n");
        }
      }


      calculateScrollbarWeight
          = client.getVerticalScrollbarWeight() == null || client.getHorizontalScrollbarWeight() == null;
      if (calculateScrollbarWeight) {
        facesContext.getOnloadScripts().add(
            "Tobago.calculateScrollbarWeights('" + clientId + ComponentUtils.SUB_SEPARATOR + "scrollbarWeight" + "');");
      } else {
        facesContext.getOnloadScripts().add(
            "Tobago.Config.set('Tobago', 'verticalScrollbarWeight', '"
                + client.getVerticalScrollbarWeight().getPixel() + "');");
        facesContext.getOnloadScripts().add(
            "Tobago.Config.set('Tobago', 'horizontalScrollbarWeight', '"
                + client.getHorizontalScrollbarWeight().getPixel() + "');");
      }

      UIComponent command = null;
      if (component.getFacets().containsKey(Facets.RESIZE_ACTION)) {
        Deprecation.LOG.warn("Please use 'resize' instead of 'resizeAction' as facet.");
        UIComponent facet = component.getFacet(Facets.RESIZE_ACTION);
        if (facet instanceof UICommand) {
          command = facet;
        } else if (facet instanceof UIForm && facet.getChildCount() == 1) {
          Deprecation.LOG.warn("Please don't use a form, but a command with immediate=true instead.");
          command = (UIComponent) facet.getChildren().get(0);
        }
      }

      if (component.getFacets().containsKey(Facets.RESIZE)) {
        UIComponent facet = component.getFacet(Facets.RESIZE);
        if (facet instanceof UICommand) {
          command = facet;
        } else if (facet instanceof UIForm && facet.getChildCount() == 1) {
          Deprecation.LOG.warn("Please don't use a form, but a command with immediate=true instead.");
          command = (UIComponent) facet.getChildren().get(0);
        }
      }
      if (command != null && command.isRendered()) {
        final CommandRendererHelper helper = new CommandRendererHelper(facesContext, (AbstractUICommandBase) command);
        if (!helper.isDisabled()) {
          writer.writeJavascript("Tobago.resizeAction = function() {\n" + helper.getOnclick() + "\n};\n");
        }
      }

      writer.startJavascript();
      // onload script
      writeEventFunction(writer, facesContext.getOnloadScripts(), "load", false);

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

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

      writeEventFunction(writer, facesContext.getOnsubmitScripts(), "submit", true);

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

        if (LOG.isDebugEnabled()) {
          LOG.debug("write scriptblock " + ++debugCounter + " :\n" + scriptBlock);
        }
        writer.write(scriptBlock);
        writer.write('\n');
      }
      writer.endJavascript();
      writer.endElement(HtmlElements.HEAD);
    }

    String defaultActionId = page.getDefaultActionId() != null ? page.getDefaultActionId() : "";
    writer.startElement(HtmlElements.BODY, page);
    writer.writeAttribute(HtmlAttributes.ONLOAD, "Tobago.init('" + clientId + "');", false);
//    writer.writeAttribute("onunload", "Tobago.onexit();", null);
    writer.writeIdAttribute(clientId);
    writer.writeClassAttribute(Classes.create(page));

    writer.startJavascript();
    writer.write("Tobago.pngFixBlankImage = '");
    writer.write(ResourceManagerUtils.getImageWithPath(facesContext, "image/blank.gif"));
    writer.write("';\n");
    writer.write("Tobago.OVERLAY_BACKGROUND = '");
    writer.write(ResourceManagerUtils.getImageWithPath(facesContext, "image/tobago-overlay-background.png"));
    writer.write("';\n");
    writer.write("Tobago.OVERLAY_WAIT = '");
    writer.write(ResourceManagerUtils.getImageWithPath(facesContext, "image/tobago-overlay-wait.gif"));
    writer.write("';\n");
    writer.endJavascript();
/*
    if (debugMode) {
      final String[] jsFiles = new String[]{
          "script/logging.js"
      };
      final String[] jsCommand = new String[]{"new LOG.LogArea({hide: " + hideClientLogging + "});"};
      HtmlRendererUtils.writeScriptLoader(facesContext, jsFiles, jsCommand);
      writer.writeJavascript("TbgTimer.startBody = new Date();");
    }
*/
    if (debugMode) {
      writer.writeJavascript("TbgTimer.startBody = new Date();");
    }

    writer.startElement(HtmlElements.FORM, page);
    writer.writeAttribute(HtmlAttributes.ACTION, formAction, true);
    writer.writeIdAttribute(page.getFormId(facesContext));
    writer.writeAttribute(HtmlAttributes.METHOD, getMethod(page), false);
    String enctype = facesContext.getEnctype();
    if (enctype != null) {
      writer.writeAttribute(HtmlAttributes.ENCTYPE, enctype, false);
    }
    // TODO: enable configuration of  'accept-charset'
    writer.writeAttribute(HtmlAttributes.ACCEPT_CHARSET, AbstractUIPage.FORM_ACCEPT_CHARSET, false);
    // TODO evaluate 'accept' attribute usage
    //writer.writeAttribute(HtmlAttributes.ACCEPT, );
    writer.startElement(HtmlElements.INPUT, null);
    writer.writeAttribute(HtmlAttributes.TYPE, "hidden", false);
    writer.writeNameAttribute(clientId + ComponentUtils.SUB_SEPARATOR + "form-action");
    writer.writeIdAttribute(clientId + ComponentUtils.SUB_SEPARATOR + "form-action");
    writer.writeAttribute(HtmlAttributes.VALUE, defaultActionId, true);
    writer.endElement(HtmlElements.INPUT);

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

    writer.startElement(HtmlElements.INPUT, null);
    writer.writeAttribute(HtmlAttributes.TYPE, "hidden", false);
    writer.writeNameAttribute(clientId + ComponentUtils.SUB_SEPARATOR + "action-position");
View Full Code Here

Examples of org.apache.myfaces.tobago.context.TobagoFacesContext

//  }

  @Override
  public void encodeEnd(FacesContext facesContextOrg, UIComponent component) throws IOException {

    TobagoFacesContext facesContext;
    if (facesContextOrg instanceof TobagoFacesContext) {
      facesContext = (TobagoFacesContext) facesContextOrg;
    } else {
      facesContext = new TobagoFacesContext(facesContextOrg);
    }

    UIPage page = (UIPage) component;
    TobagoResponseWriter writer = HtmlRendererUtils.getTobagoResponseWriter(facesContext);

    writer.endElement(HtmlElements.DIV);

    // write popup components
    // beware of ConcurrentModificationException in cascading popups!
    // no foreach
    UIPopup[] popupArray = facesContext.getPopups().toArray(new UIPopup[facesContext.getPopups().size()]);
    for (UIPopup popup : popupArray) {
      RenderUtils.encode(facesContext, popup);
    }

    String clientId = page.getClientId(facesContext);
    final boolean debugMode = VariableResolverUtils.resolveClientProperties(facesContext).isDebugMode();

    Application application = facesContext.getApplication();
    ViewHandler viewHandler = application.getViewHandler();

    writer.startElement(HtmlElements.SPAN, null);
    writer.writeIdAttribute(clientId + ComponentUtils.SUB_SEPARATOR + "jsf-state-container");
    writer.flush();
    if (!facesContext.isAjax()) {
      if (FacesVersion.supports12()) {
        viewHandler.writeState(facesContext);
      } else {
        // 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;
        facesContext.setResponseWriter(writer);

        if (StringUtils.isBlank(stateContent)) {
          if (LOG.isDebugEnabled()) {
            LOG.debug("Writing state will not happen! So we write the hidden field manually.");
          }
          writer.startElement(HtmlElements.INPUT, null);
          writer.writeAttribute(HtmlAttributes.TYPE, "hidden", false);
          writer.writeAttribute(HtmlAttributes.NAME, TobagoResponseStateManager.TREE_PARAM, false);
          writer.writeAttribute(HtmlAttributes.ID, TobagoResponseStateManager.TREE_PARAM, false);
          writer.writeAttribute(HtmlAttributes.VALUE, "workaround", false);
          writer.endElement(HtmlElements.INPUT);
        } else {
          writer.write(stateContent);
        }
      }
    }
    writer.endElement(HtmlElements.SPAN);

    // avoid submit page in ie if the form contains only one input and you press the enter key in the input
    if (VariableResolverUtils.resolveClientProperties(facesContext).getUserAgent().isMsie()) {
      writer.startElement(HtmlElements.INPUT, null);
      writer.writeAttribute(HtmlAttributes.TYPE, HtmlInputTypes.TEXT, false);
      writer.writeAttribute(HtmlAttributes.NAME, "tobago.dummy", false);
      writer.writeAttribute(HtmlAttributes.TABINDEX, "-1", false);
      writer.writeAttribute(HtmlAttributes.STYLE, "visibility:hidden;display:none;", false);
      writer.endElement(HtmlElements.INPUT);
    }

    List<String> messageClientIds = AjaxInternalUtils.getMessagesClientIds(facesContext);
    if (messageClientIds != null) {
      writer.startElement(HtmlElements.INPUT, null);
      writer.writeAttribute(HtmlAttributes.VALUE, StringUtils.join(messageClientIds, ','), true);
      writer.writeAttribute(HtmlAttributes.ID, clientId + ComponentUtils.SUB_SEPARATOR + "messagesClientIds", false);
      writer.writeAttribute(HtmlAttributes.NAME, clientId + ComponentUtils.SUB_SEPARATOR + "messagesClientIds", false);
      writer.writeAttribute(HtmlAttributes.TYPE, "hidden", false);
      writer.endElement(HtmlElements.INPUT);
    }

    // placeholder for menus
    writer.startElement(HtmlElements.DIV, page);
    writer.writeClassAttribute(Classes.create(page, "menuStore"));
    writer.endElement(HtmlElements.DIV);
   
    writer.endElement(HtmlElements.FORM);

    // debugging...
    if (debugMode) {
      List<String> logMessages = new ArrayList<String>();
      for (Iterator ids = facesContext.getClientIdsWithMessages();
           ids.hasNext();) {
        String id = (String) ids.next();
        for (Iterator messages = facesContext.getMessages(id);
             messages.hasNext();) {
          FacesMessage message = (FacesMessage) messages.next();
          logMessages.add(errorMessageForDebugging(id, message));
        }
       
      }
      if (!logMessages.isEmpty()) {
        logMessages.add(0, "LOG.show();");
      }

      logMessages.add("LOG.info(\"FacesContext = " + facesContext + "\");");

      HtmlRendererUtils.writeScriptLoader(facesContext, null,
          logMessages.toArray(new String[logMessages.size()]));
    }

    if (debugMode) {
      writer.writeJavascript("TbgTimer.endBody = new Date();");
    }

    writer.writeJavascript("setTimeout(\"Tobago.init('" + clientId + "')\", 1000)");

    writer.endElement(HtmlElements.BODY);

    if (LOG.isDebugEnabled()) {
      LOG.debug("unused AccessKeys    : "
          + AccessKeyMap.getUnusedKeys(facesContext));
      LOG.debug("duplicated AccessKeys: "
          + AccessKeyMap.getDublicatedKeys(facesContext));
    }

    if (facesContext.getExternalContext().getRequestParameterMap().get("X") != null) {
      throw new RuntimeException("Debugging activated via X parameter");
    }
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.