ICEfaces
  1. ICEfaces
  2. ICE-1991

FacesContext not accessible in ViewListener.viewDisposed()

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.6
    • Fix Version/s: 1.6.1
    • Component/s: ICE-Components
    • Labels:
      None
    • Environment:
      n/a

      Description

      FacesContext.getCurrentInstance() is null in ViewListener.viewDisposed(). Which seems strange because at this point FacesContext.dispose() hasn't been called.

        Activity

        Hide
        Philip Breau added a comment -

        suggested fix: pass a reference to the FacesContext in viewDisposed():

        Index: D:/Documents and Settings/pbreau/workspace/ICEfaces/core/src/com/icesoft/faces/context/View.java
        ===================================================================
        — D:/Documents and Settings/pbreau/workspace/ICEfaces/core/src/com/icesoft/faces/context/View.java (revision 14642)
        +++ D:/Documents and Settings/pbreau/workspace/ICEfaces/core/src/com/icesoft/faces/context/View.java (working copy)
        @@ -1,5 +1,17 @@
        package com.icesoft.faces.context;

        +import java.util.ArrayList;
        +import java.util.Collection;
        +import java.util.Collections;
        +import java.util.Iterator;
        +import java.util.Map;
        +
        +import javax.servlet.http.HttpServletRequest;
        +import javax.servlet.http.HttpServletResponse;
        +
        +import org.apache.commons.logging.Log;
        +import org.apache.commons.logging.LogFactory;
        +
        import com.icesoft.faces.env.PortletEnvironmentRenderRequest;
        import com.icesoft.faces.env.ServletEnvironmentRequest;
        import com.icesoft.faces.webapp.command.Command;
        @@ -13,19 +25,10 @@
        import com.icesoft.faces.webapp.http.servlet.SessionDispatcher;
        import com.icesoft.faces.webapp.xmlhttp.PersistentFacesState;
        import com.icesoft.util.SeamUtilities;
        +
        import edu.emory.mathcs.backport.java.util.concurrent.locks.Lock;
        import edu.emory.mathcs.backport.java.util.concurrent.locks.ReentrantLock;
        -import org.apache.commons.logging.Log;
        -import org.apache.commons.logging.LogFactory;

        -import javax.servlet.http.HttpServletRequest;
        -import javax.servlet.http.HttpServletResponse;
        -import java.util.ArrayList;
        -import java.util.Collection;
        -import java.util.Collections;
        -import java.util.Iterator;
        -import java.util.Map;
        -
        public class View implements CommandQueue {
        private static final Log Log = LogFactory.getLog(View.class);
        private static final NOOP NOOP = new NOOP();
        @@ -43,7 +46,7 @@
        private String sessionID;
        private Configuration configuration;
        private SessionDispatcher.Listener.Monitor sessionMonitor;
        -
        +
        public View(final String viewIdentifier, String sessionID, Request request, final ViewQueue allServedViews, final Configuration configuration, final SessionDispatcher.Listener.Monitor sessionMonitor) throws Exception

        { this.sessionID = sessionID; this.configuration = configuration; @@ -199,7 +202,7 @@ facesContext.applyBrowserDOMChanges(); }
        • private void notifyViewCreation() {
          + public void notifyViewCreation() {
          Iterator i = viewListeners.iterator();
          while (i.hasNext()) {
          try {
          @@ -216,7 +219,7 @@
          while (i.hasNext()) {
          try { ViewListener listener = (ViewListener) i.next(); - listener.viewDisposed(); + listener.viewDisposed(facesContext); }

          catch (Throwable t)

          { Log.warn("Failed to invoke view listener", t); }

          Index: D:/Documents and Settings/pbreau/workspace/ICEfaces/core/src/com/icesoft/faces/context/ViewListener.java
          ===================================================================

            • D:/Documents and Settings/pbreau/workspace/ICEfaces/core/src/com/icesoft/faces/context/ViewListener.java (revision 14642)
              +++ D:/Documents and Settings/pbreau/workspace/ICEfaces/core/src/com/icesoft/faces/context/ViewListener.java (working copy)
              @@ -1,5 +1,7 @@
              package com.icesoft.faces.context;

        +import javax.faces.context.FacesContext;
        +
        public interface ViewListener

        { /** @@ -11,6 +13,6 @@ * View has been disposed either by window closing * or timeout. */ - void viewDisposed(); + void viewDisposed(FacesContext context); }

        Index: D:/Documents and Settings/pbreau/workspace/ICEfaces/core/src/com/icesoft/faces/context/DOMResponseWriter.java
        ===================================================================
        — D:/Documents and Settings/pbreau/workspace/ICEfaces/core/src/com/icesoft/faces/context/DOMResponseWriter.java (revision 14642)
        +++ D:/Documents and Settings/pbreau/workspace/ICEfaces/core/src/com/icesoft/faces/context/DOMResponseWriter.java (working copy)
        @@ -66,257 +66,258 @@
        import java.util.Map;

        /**

        • * <p><strong>DOMResponseWriter</strong> is a DOM specific implementation of
          + * <p>
          + * <strong>DOMResponseWriter</strong> is a DOM specific implementation of
        • <code>javax.faces.context.ResponseWriter</code>.
          */
          public class DOMResponseWriter extends ResponseWriter {
        • private static final Log log = LogFactory.getLog(DOMResponseWriter.class);
        • public static final String STREAM_WRITING = "com.icesoft.faces.streamWriting";
        • //DOM and current node being written to for this ResponseWriter
        • public static final String DOCTYPE_PUBLIC = "com.icesoft.doctype.public";
        • public static final String DOCTYPE_SYSTEM = "com.icesoft.doctype.system";
        • public static final String DOCTYPE_ROOT = "com.icesoft.doctype.root";
        • public static final String DOCTYPE_OUTPUT = "com.icesoft.doctype.output";
        • public static final String DOCTYPE_PRETTY_PRINTING =
        • "com.icesoft.doctype.prettyprinting";
          + private static final Log log = LogFactory.getLog(DOMResponseWriter.class);
          + public static final String STREAM_WRITING = "com.icesoft.faces.streamWriting";
          + // DOM and current node being written to for this ResponseWriter
          + public static final String DOCTYPE_PUBLIC = "com.icesoft.doctype.public";
          + public static final String DOCTYPE_SYSTEM = "com.icesoft.doctype.system";
          + public static final String DOCTYPE_ROOT = "com.icesoft.doctype.root";
          + public static final String DOCTYPE_OUTPUT = "com.icesoft.doctype.output";
          + public static final String DOCTYPE_PRETTY_PRINTING = "com.icesoft.doctype.prettyprinting";
        • public static final String RESPONSE_DOM = "com.icesoft.domResponseDocument";
        • public static final String RESPONSE_DOM_ID =
        • "com.icesoft.domResponseDocumentID";
        • public static final String OLD_DOM = "com.icesoft.oldDocument";
        • public static final String RESPONSE_VIEWROOT =
        • "com.icesoft.domResponseViewRoot";
        • //Hashtable of DOMContext objects associated with each component
        • public static final String RESPONSE_CONTEXTS_TABLE =
        • "com.icesoft.domResponseContexts";
        • private static DocumentBuilder DOCUMENT_BUILDER;
          + public static final String RESPONSE_DOM = "com.icesoft.domResponseDocument";
          + public static final String RESPONSE_DOM_ID = "com.icesoft.domResponseDocumentID";
          + public static final String OLD_DOM = "com.icesoft.oldDocument";
          + public static final String RESPONSE_VIEWROOT = "com.icesoft.domResponseViewRoot";
          + // Hashtable of DOMContext objects associated with each component
          + public static final String RESPONSE_CONTEXTS_TABLE = "com.icesoft.domResponseContexts";
          + private static DocumentBuilder DOCUMENT_BUILDER;
        • static {
        • try { - DOCUMENT_BUILDER = - DocumentBuilderFactory.newInstance().newDocumentBuilder(); - }

          catch (ParserConfigurationException e)

          { - log.error("Cannot acquire a DocumentBuilder", e); - }
        • }
          + static
          Unknown macro: {+ try { + DOCUMENT_BUILDER = DocumentBuilderFactory.newInstance() + .newDocumentBuilder(); + } catch (ParserConfigurationException e) { + log.error("Cannot acquire a DocumentBuilder", e); + }+ }
        • private static boolean isStreamWritingFlag = false;
        • private Document document;
        • private Node cursor;
        • private Map domResponseContexts;
        • private Map contextServletTable;
        • private BridgeFacesContext context;
        • private DOMSerializer serializer;
        • private Configuration configuration;
          + private static boolean isStreamWritingFlag = false;
          + private Document document;
          + private Node cursor;
          + private Map domResponseContexts;
          + private Map contextServletTable;
          + private BridgeFacesContext context;
          + private DOMSerializer serializer;
          + private Configuration configuration;
        • public DOMResponseWriter(FacesContext context, DOMSerializer serializer, Configuration configuration) {
        • this.serializer = serializer;
        • this.configuration = configuration;
        • try { - this.context = (BridgeFacesContext) context; - }

          catch (ClassCastException e)

          { - throw new IllegalStateException( - "ICEfaces requires the PersistentFacesServlet. " + - "Please check your web.xml servlet mappings"); - }
        • this.initialize();
        • }
          + public DOMResponseWriter(FacesContext context, DOMSerializer serializer,
          + Configuration configuration)
          Unknown macro: {+ this.serializer = serializer;+ this.configuration = configuration;+ try { + this.context = (BridgeFacesContext) context; + } catch (ClassCastException e) { + throw new IllegalStateException( + "ICEfaces requires the PersistentFacesServlet. " + + "Please check your web.xml servlet mappings"); + }+ this.initialize();+ }
        • Map getDomResponseContexts() { - return domResponseContexts; - }

          + Map getDomResponseContexts()

          { + return domResponseContexts; + }
        • public Node getCursorParent() { - return cursor; - }

          + public Node getCursorParent()

          { + return cursor; + }
        • public Document getDocument() { - return document; - }

          + public Document getDocument()

          { + return document; + }
        • public String getContentType() { - return "text/html; charset=UTF-8"; - }

          + public String getContentType()

          { + return "text/html; charset=UTF-8"; + }
        • public String getCharacterEncoding() { - return "UTF-8"; - }

          + public String getCharacterEncoding()

          { + return "UTF-8"; + }
        • public void startDocument() throws IOException { - }
          + public void startDocument() throws IOException { + }

          - private void initialize() {
          - contextServletTable = D2DViewHandler.getContextServletTable(context);
          - // contexts for each component
          - if (contextServletTable
          - .containsKey(DOMResponseWriter.RESPONSE_CONTEXTS_TABLE)) { - domResponseContexts = (Map) contextServletTable - .get(DOMResponseWriter.RESPONSE_CONTEXTS_TABLE); - }
          - if (null == domResponseContexts) { - domResponseContexts = new HashMap(); - contextServletTable.put(DOMResponseWriter.RESPONSE_CONTEXTS_TABLE, - domResponseContexts); - }
          - // viewroot, application
          - contextServletTable.put(DOMResponseWriter.RESPONSE_VIEWROOT,
          - context.getViewRoot());
          - cursor = document = DOCUMENT_BUILDER.newDocument();
          - contextServletTable.put(DOMResponseWriter.RESPONSE_DOM, document);
          - boolean streamWritingParam = "true".equalsIgnoreCase(
          - context.getExternalContext().getInitParameter(
          - DOMResponseWriter.STREAM_WRITING));
          - DOMResponseWriter.isStreamWritingFlag =
          - Beans.isDesignTime() || streamWritingParam;
          - }
          + private void initialize() {
          + contextServletTable = D2DViewHandler.getContextServletTable(context);
          + // contexts for each component
          + if (contextServletTable
          + .containsKey(DOMResponseWriter.RESPONSE_CONTEXTS_TABLE)) { + domResponseContexts = (Map) contextServletTable + .get(DOMResponseWriter.RESPONSE_CONTEXTS_TABLE); + }
          + if (null == domResponseContexts) { + domResponseContexts = new HashMap(); + contextServletTable.put(DOMResponseWriter.RESPONSE_CONTEXTS_TABLE, + domResponseContexts); + }
          + // viewroot, application
          + contextServletTable.put(DOMResponseWriter.RESPONSE_VIEWROOT, context
          + .getViewRoot());
          + cursor = document = DOCUMENT_BUILDER.newDocument();
          + contextServletTable.put(DOMResponseWriter.RESPONSE_DOM, document);
          + boolean streamWritingParam = "true".equalsIgnoreCase(context
          + .getExternalContext().getInitParameter(
          + DOMResponseWriter.STREAM_WRITING));
          + DOMResponseWriter.isStreamWritingFlag = Beans.isDesignTime()
          + || streamWritingParam;
          + }

          - public void endDocument() throws IOException {
          - if (!isStreamWriting()) { - enhanceAndFixDocument(); - serializer.serialize(document); - }
          - }
          + public void endDocument() throws IOException {
          + if (!isStreamWriting()) { + enhanceAndFixDocument(); + serializer.serialize(document); + }
          + }

          - public void flush() throws IOException { - }

          + public void flush() throws IOException

          { + }

          - public void startElement(String name, UIComponent componentForElement)
          - throws IOException {
          - Node oldCursor = cursor;
          - Element elem = document.createElement(name);
          - cursor = cursor.appendChild(elem);
          - if (log.isTraceEnabled()) { - log.trace("startElement() name: " + name + " elem: " + elem + - " oldCursor: " + oldCursor + " newCursor: " + cursor); - }
          - }
          + public void startElement(String name, UIComponent componentForElement)
          + throws IOException {
          + Node oldCursor = cursor;
          + Element elem = document.createElement(name);
          + if (log.isTraceEnabled()) { + log.trace("attempting startElement() name: " + name + " elem: " + + elem + " oldCursor: " + oldCursor); + }
          + cursor = cursor.appendChild(elem);
          + if (log.isTraceEnabled()) { + log.trace("startElement() newCursor: " + cursor); + }
          + }

          - public void endElement(String name) throws IOException {
          - Node oldCursor = cursor;
          - cursor = cursor.getParentNode();
          - if (log.isTraceEnabled()) { - log.trace("endElement() name: " + name + " oldCursor: " + - oldCursor + " newCursor: " + cursor); - }
          - }
          + public void endElement(String name) throws IOException {
          + Node oldCursor = cursor;
          + cursor = cursor.getParentNode();
          + if (log.isTraceEnabled()) { + log.trace("endElement() name: " + name + " oldCursor: " + + oldCursor + " newCursor: " + cursor); + }
          + }

          - public void writeAttribute(String name, Object value,
          - String componentPropertyName)
          - throws IOException { - //name.trim() because cardemo had a leading space in an attribute name - //which made the DOM processor choke - ((Element) cursor).setAttribute(name.trim(), String.valueOf(value)); - }
          + public void writeAttribute(String name, Object value,
          + String componentPropertyName) throws IOException { + // name.trim() because cardemo had a leading space in an attribute name + // which made the DOM processor choke + ((Element) cursor).setAttribute(name.trim(), String.valueOf(value)); + }

          - public void writeURIAttribute(String name, Object value,
          - String componentPropertyName)
          - throws IOException {
          - String stringValue = String.valueOf(value);
          - if (stringValue.startsWith("javascript:")) { - ((Element) cursor).setAttribute(name, stringValue); - } else { - ((Element) cursor) - .setAttribute(name, stringValue.replace(' ', '+')); - }
          - }
          + public void writeURIAttribute(String name, Object value,
          + String componentPropertyName) throws IOException {
          + String stringValue = String.valueOf(value);
          + if (stringValue.startsWith("javascript:")) { + ((Element) cursor).setAttribute(name, stringValue); + } else { + ((Element) cursor) + .setAttribute(name, stringValue.replace(' ', '+')); + }
          + }

          - public void writeComment(Object comment) throws IOException {
          - if (log.isTraceEnabled()) { - log.trace("writeComment() comment: " + comment); - }
          - cursor.appendChild(document.createComment(String.valueOf(comment)));
          - }
          + public void writeComment(Object comment) throws IOException {
          + if (log.isTraceEnabled()) { + log.trace("writeComment() comment: " + comment); + }
          + cursor.appendChild(document.createComment(String.valueOf(comment)));
          + }

          - public void writeText(Object text, String componentPropertyName)
          - throws IOException {
          - if (log.isTraceEnabled()) { - log.trace("writeText(O,S) text: " + text); - }
          - cursor.appendChild(document.createTextNode(String.valueOf(text)));
          - }
          + public void writeText(Object text, String componentPropertyName)
          + throws IOException {
          + if (log.isTraceEnabled()) { + log.trace("writeText(O,S) text: " + text); + }
          + cursor.appendChild(document.createTextNode(String.valueOf(text)));
          + }

          - public void writeText(char text[], int off, int len) throws IOException {
          - if (log.isTraceEnabled()) { - log.trace("writeText(c[],i,i) text: " + - (new String(text, off, len))); - }
          - cursor.appendChild(document.createTextNode(new String(text, off, len)));
          - }
          + public void writeText(char text[], int off, int len) throws IOException {
          + if (log.isTraceEnabled()) { + log.trace("writeText(c[],i,i) text: " + + (new String(text, off, len))); + }
          + cursor.appendChild(document.createTextNode(new String(text, off, len)));
          + }

          - public ResponseWriter cloneWithWriter(Writer writer) {
          - //FIXME: This is a hack for DOM rendering but JSF currently clones the writer
          - //just as the components are complete
          - if (null != document) {
          - try { - endDocument(); - } catch (IOException e) { - throw new IllegalStateException(e.toString()); - }
          - }
          - try { - return new DOMResponseWriter(context, serializer, configuration); - } catch (FacesException e) { - throw new IllegalStateException(); - }
          - }
          + public ResponseWriter cloneWithWriter(Writer writer) {
          + // FIXME: This is a hack for DOM rendering but JSF currently clones the
          + // writer
          + // just as the components are complete
          + if (null != document) {
          + try { + endDocument(); + } catch (IOException e) { + throw new IllegalStateException(e.toString()); + }
          + }
          + try { + return new DOMResponseWriter(context, serializer, configuration); + } catch (FacesException e) { + throw new IllegalStateException(); + }
          + }

          - public void close() throws IOException { - }
          + public void close() throws IOException { + }
        • public void write(char[] cbuf, int off, int len) throws IOException {
        • if (log.isTraceEnabled()) { - log.trace("writeText(c[],i,i) str: " + - (new String(cbuf, off, len))); - }
        • cursor.appendChild(document.createTextNode(new String(cbuf, off, len)));
        • }
          + public void write(char[] cbuf, int off, int len) throws IOException
          Unknown macro: {+ if (log.isTraceEnabled()) { + log.trace("writeText(c[],i,i) str: " + + (new String(cbuf, off, len))); + }+ cursor.appendChild(document.createTextNode(new String(cbuf, off, len)));+ }
        • public void write(int c) throws IOException {
        • if (log.isTraceEnabled()) { - log.trace("write(i) hex: " + Integer.toHexString(c) + - " decimal: " + c); - }
        • cursor.appendChild(document.createTextNode(String.valueOf((char) c)));
        • }
          + public void write(int c) throws IOException
          Unknown macro: {+ if (log.isTraceEnabled()) { + log.trace("write(i) hex: " + Integer.toHexString(c) + + " decimal: " + c); + }+ cursor.appendChild(document.createTextNode(String.valueOf((char) c)));+ }
        • public void write(String str) throws IOException {
        • if (log.isTraceEnabled()) { - log.trace("write(S) str: " + str); - }
        • cursor.appendChild(document.createTextNode(str));
        • }
          + public void write(String str) throws IOException
          Unknown macro: {+ if (log.isTraceEnabled()) { + log.trace("write(S) str: " + str); + }+ cursor.appendChild(document.createTextNode(str));+ }
        • public void write(String str, int off, int len) throws IOException {
        • if (log.isTraceEnabled()) { - log.trace("write(S,i,i) str_sub: " + str.substring(off, len)); - }
        • cursor.appendChild(document.createTextNode(str.substring(off, len)));
        • }
          + public void write(String str, int off, int len) throws IOException
          Unknown macro: {+ if (log.isTraceEnabled()) { + log.trace("write(S,i,i) str_sub: " + str.substring(off, len)); + }+ cursor.appendChild(document.createTextNode(str.substring(off, len)));+ }
        • private void enhanceAndFixDocument() {
        • Element html = (Element) document.getDocumentElement();
        • enhanceHtml(html = "html".equals(html.getTagName()) ? html : fixHtml());
          + private void enhanceAndFixDocument() { + Element html = (Element) document.getDocumentElement(); + enhanceHtml(html = "html".equals(html.getTagName()) ? html : fixHtml()); - Element head = (Element) document.getElementsByTagName("head").item(0); - enhanceHead(head == null ? fixHead() : head); + Element head = (Element) document.getElementsByTagName("head").item(0); + enhanceHead(head == null ? fixHead() : head); - Element body = (Element) document.getElementsByTagName("body").item(0); - enhanceBody(body == null ? fixBody() : body); - }

          + Element body = (Element) document.getElementsByTagName("body").item(0);
          + enhanceBody(body == null ? fixBody() : body);
          + }

        • private void enhanceHtml(Element html) { - //add lang attribute - Locale locale = context.getApplication().getViewHandler().calculateLocale(context); - html.setAttribute("lang", locale.getLanguage()); - }

          + private void enhanceHtml(Element html)

          { + // add lang attribute + Locale locale = context.getApplication().getViewHandler() + .calculateLocale(context); + html.setAttribute("lang", locale.getLanguage()); + }
        • private void enhanceBody(Element body) {
        • //id required for forwarded (server-side) redirects
        • body.setAttribute("id", "body");
        • Element iframe = document.createElement("iframe");
        • body.insertBefore(iframe, body.getFirstChild());
        • iframe.setAttribute("id", "history-frame");
        • Object request = context.getExternalContext().getRequest();
          + private void enhanceBody(Element body) {
          + // id required for forwarded (server-side) redirects
          + body.setAttribute("id", "body");
          + Element iframe = document.createElement("iframe");
          + body.insertBefore(iframe, body.getFirstChild());
          + iframe.setAttribute("id", "history-frame");
          + Object request = context.getExternalContext().getRequest();

        final String frameURI;
        //another "workaround" to resolve the iframe URI
        @@ -337,150 +338,185 @@
        iframe.setAttribute("style",
        "z-index: 10000; visibility: hidden; width: 0; height: 0; position: absolute; opacity: 0.22; filter: alpha(opacity=22);");

        • // TODO This is only meant to be a transitional focus retention(management) solution.
        • String focusId = context.getFocusId();
        • if (focusId != null && !focusId.equals("null")) { - JavascriptContext.focus(context, focusId); - }

          + // TODO This is only meant to be a transitional focus
          + // retention(management) solution.
          + String focusId = context.getFocusId();
          + if (focusId != null && !focusId.equals("null"))

          { + JavascriptContext.focus(context, focusId); + }
        • Element script =
        • (Element) body.appendChild(document.createElement("script"));
        • script.setAttribute("id", JavascriptContext.DYNAMIC_CODE_ID);
        • script.setAttribute("language", "javascript");
        • String calls = JavascriptContext.getJavascriptCalls(context);
        • script.appendChild(document.createTextNode(calls));
          + Element script = (Element) body.appendChild(document
          + .createElement("script"));
          + script.setAttribute("id", JavascriptContext.DYNAMIC_CODE_ID);
          + script.setAttribute("language", "javascript");
          + String calls = JavascriptContext.getJavascriptCalls(context);
          + script.appendChild(document.createTextNode(calls));
        • Map session = context.getExternalContext().getSessionMap();
        • ElementController.from(session).addInto(body);
          + Map session = context.getExternalContext().getSessionMap();
          + ElementController.from(session).addInto(body);
        • String sessionIDScript = "window.session='" + context.getIceFacesId() + "';\n";
        • //add viewIdentifier property to the container element ("body" for servlet env., any element for the portlet env.)
        • String viewIDScript = "document.getElementById('configuration-script').parentNode.viewIdentifier=" + context.getViewNumber() + ";\n";
        • String viewsIDScript = "if (!window.views) window.views = []; window.views.push(" + context.getViewNumber() + ");\n";
          + String sessionIDScript = "window.session='" + context.getIceFacesId()
          + + "';\n";
          + // add viewIdentifier property to the container element ("body" for
          + // servlet env., any element for the portlet env.)
          + String viewIDScript = "document.getElementById('configuration-script').parentNode.viewIdentifier="
          + + context.getViewNumber() + ";\n";
          + String viewsIDScript = "if (!window.views) window.views = []; window.views.push("
          + + context.getViewNumber() + ");\n";
        • String configurationScript =
        • "window.configuration = {" +
        • "synchronous: " + configuration.getAttribute("synchronousUpdate", "false") + "," +
        • "redirectURI: " + configuration.getAttribute("connectionLostRedirectURI", "null") + "," +
        • "connection: {" +
        • "context: '" + context.getApplication().getViewHandler().getResourceURL(context, "/") + "'," +
        • "timeout: " + configuration.getAttributeAsLong("connectionTimeout", 30000) + "," +
        • "heartbeat: {" + - "interval: " + configuration.getAttributeAsLong("heartbeatInterval", 20000) + "," + - "timeout: " + configuration.getAttributeAsLong("heartbeatTimeout", 3000) + "," + - "retries: " + configuration.getAttributeAsLong("heartbeatRetries", 3) + - "}

          " +

        • "}" +
        • "};\n";
          + String configurationScript = "window.configuration = {"
          + + "synchronous: "
          + + configuration.getAttribute("synchronousUpdate", "false")
          + + ","
          + + "redirectURI: "
          + + configuration.getAttribute("connectionLostRedirectURI",
          + "null")
          + + ","
          + + "connection:
          Unknown macro: {"+ + "context}

          " + "};\n";

        • Element configurationElement = (Element) body.appendChild(document.createElement("script"));
        • configurationElement.setAttribute("id", "configuration-script");
        • configurationElement.setAttribute("language", "javascript");
        • configurationElement.appendChild(document.createTextNode(sessionIDScript + viewIDScript + viewsIDScript + configurationScript));
        • body.appendChild(configurationElement);
        • }
          + Element configurationElement = (Element) body.appendChild(document
          + .createElement("script"));
          + configurationElement.setAttribute("id", "configuration-script");
          + configurationElement.setAttribute("language", "javascript");
          + configurationElement.appendChild(document
          + .createTextNode(sessionIDScript + viewIDScript + viewsIDScript
          + + configurationScript));
          + body.appendChild(configurationElement);
          + }
        • private void enhanceHead(Element head) {
        • ViewHandler handler = context.getApplication().getViewHandler();
        • //id required for forwarded (server-side) redirects
        • head.setAttribute("id", "head");
        • Element meta =
        • (Element) head.appendChild(document.createElement("meta"));
        • meta.setAttribute("name", "icefaces");
        • meta.setAttribute("content", "Rendered by ICEFaces D2D");
          + private void addNoScriptIfNotAlreadyAdded(Element head)
          Unknown macro: {+ + NodeList list = head.getElementsByTagName("noscript");+ if( list.getLength() == 0 ){ + Element noscript = (Element) head.appendChild(document + .createElement("noscript")); + Element noscriptMeta = (Element) noscript.appendChild(document + .createElement("meta")); + noscriptMeta.setAttribute("http-equiv", "refresh"); + noscriptMeta.setAttribute("content", "0;url=" + + context.getApplication().getViewHandler().getResourceURL( + context, "/xmlhttp/javascript-blocked")); + }+ }
        • Element noscript =
        • (Element) head.appendChild(document.createElement("noscript"));
        • Element noscriptMeta =
        • (Element) noscript.appendChild(document.createElement("meta"));
        • noscriptMeta.setAttribute("http-equiv", "refresh");
        • noscriptMeta
        • .setAttribute("content", "0;url=" + handler.getResourceURL(context, "/xmlhttp/javascript-blocked"));
          + private void enhanceHead(Element head) {
          + ViewHandler handler = context.getApplication().getViewHandler();
          + // id required for forwarded (server-side) redirects
          + head.setAttribute("id", "head");
          + Element meta = (Element) head.appendChild(document
          + .createElement("meta"));
          + meta.setAttribute("name", "icefaces");
          + meta.setAttribute("content", "Rendered by ICEFaces D2D");
        • //load libraries
        • Collection libs = new ArrayList();
        • if (context.getExternalContext().getInitParameter(D2DViewHandler.INCLUDE_OPEN_AJAX_HUB) != null) { - libs.add("/xmlhttp/openajax.js"); - }
        • libs.add("/xmlhttp" + StartupTime.getStartupInc() + "icefaces-d2d.js");
        • //todo: refactor how extral libraries are loaded into the bridge; always include extra libraries for now
        • libs.add("/xmlhttp" + StartupTime.getStartupInc() + "ice-extras.js");
        • if (context.getExternalContext().getRequestMap().get(Constants.INC_SERVLET_PATH) == null) {
        • String[] componentLibs = JavascriptContext.getIncludedLibs(context);
        • for (int i = 0; i < componentLibs.length; i++) {
        • String componentLib = componentLibs[i];
        • if (!libs.contains(componentLib)) { - libs.add(componentLib); - }
        • }
        • }
          + addNoScriptIfNotAlreadyAdded(head);
        • Iterator iterator = libs.iterator();
        • while (iterator.hasNext()) { - String lib = (String) iterator.next(); - Element script = (Element) head - .appendChild(document.createElement("script")); - script.setAttribute("language", "javascript"); - script.setAttribute("src", handler.getResourceURL(context, lib)); - }

          + // load libraries
          + Collection libs = new ArrayList();
          + if (context.getExternalContext().getInitParameter(
          + D2DViewHandler.INCLUDE_OPEN_AJAX_HUB) != null)

          { + libs.add("/xmlhttp/openajax.js"); + }

          + libs.add("/xmlhttp" + StartupTime.getStartupInc() + "icefaces-d2d.js");
          + // todo: refactor how extral libraries are loaded into the bridge;
          + // always include extra libraries for now
          + libs.add("/xmlhttp" + StartupTime.getStartupInc() + "ice-extras.js");
          + if (context.getExternalContext().getRequestMap().get(
          + Constants.INC_SERVLET_PATH) == null) {
          + String[] componentLibs = JavascriptContext.getIncludedLibs(context);
          + for (int i = 0; i < componentLibs.length; i++)

          Unknown macro: {+ String componentLib = componentLibs[i];+ if (!libs.contains(componentLib)) { + libs.add(componentLib); + }+ }

          + }

        • String sessionIdentifier = context.getIceFacesId();
        • Element viewAndSessionScript = (Element) head.appendChild(document.createElement("script"));
        • viewAndSessionScript.setAttribute("language", "javascript");
        • viewAndSessionScript.appendChild(document.createTextNode(
        • "window.session = '" + sessionIdentifier + "';"
        • ));
        • }
          + Iterator iterator = libs.iterator();
          + while (iterator.hasNext()) { + String lib = (String) iterator.next(); + Element script = (Element) head.appendChild(document + .createElement("script")); + script.setAttribute("language", "javascript"); + script.setAttribute("src", handler.getResourceURL(context, lib)); + }
        • private Element fixHtml() { - Element root = document.getDocumentElement(); - Element html = document.createElement("html"); - document.replaceChild(html, root); - html.appendChild(root); + String sessionIdentifier = context.getIceFacesId(); + Element viewAndSessionScript = (Element) head.appendChild(document + .createElement("script")); + viewAndSessionScript.setAttribute("language", "javascript"); + viewAndSessionScript + .appendChild(document.createTextNode("window.session = '" + + sessionIdentifier + "';")); + }
        • return html;
        • }
          + private Element fixHtml() {
          + Element root = document.getDocumentElement();
          + Element html = document.createElement("html");
          + document.replaceChild(html, root);
          + html.appendChild(root);
        • private Element fixBody() {
        • Element html = document.getDocumentElement();
        • Element body = document.createElement("body");
        • NodeList children = html.getChildNodes();
        • int length = children.getLength();
        • Node[] nodes = new Node[length];
        • //copy the children first, since NodeList is live
        • for (int i = 0; i < nodes.length; i++) nodes[i] = children.item;
        • for (int i = 0; i < nodes.length; i++) { - Node node = nodes[i]; - if (!(node instanceof Element && - "head".equals(((Element) node).getTagName()))) - body.appendChild(node); - }
        • html.appendChild(body);
          + return html;
          + }
        • return body;
        • }
          + private Element fixBody() {
          + Element html = document.getDocumentElement();
          + Element body = document.createElement("body");
          + NodeList children = html.getChildNodes();
          + int length = children.getLength();
          + Node[] nodes = new Node[length];
          + // copy the children first, since NodeList is live
          + for (int i = 0; i < nodes.length; i++)
          + nodes[i] = children.item;
          + for (int i = 0; i < nodes.length; i++) { + Node node = nodes[i]; + if (!(node instanceof Element && "head".equals(((Element) node) + .getTagName()))) + body.appendChild(node); + }

          + html.appendChild(body);

        • private Element fixHead() { - Element html = document.getDocumentElement(); - Element head = document.createElement("head"); - html.insertBefore(head, html.getFirstChild()); + return body; + }
        • return head;
        • }
          + private Element fixHead() {
          + Element html = document.getDocumentElement();
          + Element head = document.createElement("head");
          + html.insertBefore(head, html.getFirstChild());
        • /**
        • * This method sets the write cursor for DOM modifications. Subsequent DOM
        • * modifications will take place below the cursor element.
        • *
        • * @param cursorParent parent node for subsequent modifications to the DOM
        • */
        • protected void setCursorParent(Node cursorParent) { - this.cursor = cursorParent; - }

          + return head;
          + }

        • public static boolean isStreamWriting() { - return isStreamWritingFlag; - }

          + /**
          + * This method sets the write cursor for DOM modifications. Subsequent DOM
          + * modifications will take place below the cursor element.
          + *
          + * @param cursorParent
          + * parent node for subsequent modifications to the DOM
          + */
          + protected void setCursorParent(Node cursorParent)

          { + this.cursor = cursorParent; + }

        + public static boolean isStreamWriting()

        { + return isStreamWritingFlag; + }

        }

        Show
        Philip Breau added a comment - suggested fix: pass a reference to the FacesContext in viewDisposed(): Index: D:/Documents and Settings/pbreau/workspace/ICEfaces/core/src/com/icesoft/faces/context/View.java =================================================================== — D:/Documents and Settings/pbreau/workspace/ICEfaces/core/src/com/icesoft/faces/context/View.java (revision 14642) +++ D:/Documents and Settings/pbreau/workspace/ICEfaces/core/src/com/icesoft/faces/context/View.java (working copy) @@ -1,5 +1,17 @@ package com.icesoft.faces.context; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.Iterator; +import java.util.Map; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + import com.icesoft.faces.env.PortletEnvironmentRenderRequest; import com.icesoft.faces.env.ServletEnvironmentRequest; import com.icesoft.faces.webapp.command.Command; @@ -13,19 +25,10 @@ import com.icesoft.faces.webapp.http.servlet.SessionDispatcher; import com.icesoft.faces.webapp.xmlhttp.PersistentFacesState; import com.icesoft.util.SeamUtilities; + import edu.emory.mathcs.backport.java.util.concurrent.locks.Lock; import edu.emory.mathcs.backport.java.util.concurrent.locks.ReentrantLock; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.Iterator; -import java.util.Map; - public class View implements CommandQueue { private static final Log Log = LogFactory.getLog(View.class); private static final NOOP NOOP = new NOOP(); @@ -43,7 +46,7 @@ private String sessionID; private Configuration configuration; private SessionDispatcher.Listener.Monitor sessionMonitor; - + public View(final String viewIdentifier, String sessionID, Request request, final ViewQueue allServedViews, final Configuration configuration, final SessionDispatcher.Listener.Monitor sessionMonitor) throws Exception { this.sessionID = sessionID; this.configuration = configuration; @@ -199,7 +202,7 @@ facesContext.applyBrowserDOMChanges(); } private void notifyViewCreation() { + public void notifyViewCreation() { Iterator i = viewListeners.iterator(); while (i.hasNext()) { try { @@ -216,7 +219,7 @@ while (i.hasNext()) { try { ViewListener listener = (ViewListener) i.next(); - listener.viewDisposed(); + listener.viewDisposed(facesContext); } catch (Throwable t) { Log.warn("Failed to invoke view listener", t); } Index: D:/Documents and Settings/pbreau/workspace/ICEfaces/core/src/com/icesoft/faces/context/ViewListener.java =================================================================== D:/Documents and Settings/pbreau/workspace/ICEfaces/core/src/com/icesoft/faces/context/ViewListener.java (revision 14642) +++ D:/Documents and Settings/pbreau/workspace/ICEfaces/core/src/com/icesoft/faces/context/ViewListener.java (working copy) @@ -1,5 +1,7 @@ package com.icesoft.faces.context; +import javax.faces.context.FacesContext; + public interface ViewListener { /** @@ -11,6 +13,6 @@ * View has been disposed either by window closing * or timeout. */ - void viewDisposed(); + void viewDisposed(FacesContext context); } Index: D:/Documents and Settings/pbreau/workspace/ICEfaces/core/src/com/icesoft/faces/context/DOMResponseWriter.java =================================================================== — D:/Documents and Settings/pbreau/workspace/ICEfaces/core/src/com/icesoft/faces/context/DOMResponseWriter.java (revision 14642) +++ D:/Documents and Settings/pbreau/workspace/ICEfaces/core/src/com/icesoft/faces/context/DOMResponseWriter.java (working copy) @@ -66,257 +66,258 @@ import java.util.Map; /** * <p><strong>DOMResponseWriter</strong> is a DOM specific implementation of + * <p> + * <strong>DOMResponseWriter</strong> is a DOM specific implementation of <code>javax.faces.context.ResponseWriter</code>. */ public class DOMResponseWriter extends ResponseWriter { private static final Log log = LogFactory.getLog(DOMResponseWriter.class); public static final String STREAM_WRITING = "com.icesoft.faces.streamWriting"; //DOM and current node being written to for this ResponseWriter public static final String DOCTYPE_PUBLIC = "com.icesoft.doctype.public"; public static final String DOCTYPE_SYSTEM = "com.icesoft.doctype.system"; public static final String DOCTYPE_ROOT = "com.icesoft.doctype.root"; public static final String DOCTYPE_OUTPUT = "com.icesoft.doctype.output"; public static final String DOCTYPE_PRETTY_PRINTING = "com.icesoft.doctype.prettyprinting"; + private static final Log log = LogFactory.getLog(DOMResponseWriter.class); + public static final String STREAM_WRITING = "com.icesoft.faces.streamWriting"; + // DOM and current node being written to for this ResponseWriter + public static final String DOCTYPE_PUBLIC = "com.icesoft.doctype.public"; + public static final String DOCTYPE_SYSTEM = "com.icesoft.doctype.system"; + public static final String DOCTYPE_ROOT = "com.icesoft.doctype.root"; + public static final String DOCTYPE_OUTPUT = "com.icesoft.doctype.output"; + public static final String DOCTYPE_PRETTY_PRINTING = "com.icesoft.doctype.prettyprinting"; public static final String RESPONSE_DOM = "com.icesoft.domResponseDocument"; public static final String RESPONSE_DOM_ID = "com.icesoft.domResponseDocumentID"; public static final String OLD_DOM = "com.icesoft.oldDocument"; public static final String RESPONSE_VIEWROOT = "com.icesoft.domResponseViewRoot"; //Hashtable of DOMContext objects associated with each component public static final String RESPONSE_CONTEXTS_TABLE = "com.icesoft.domResponseContexts"; private static DocumentBuilder DOCUMENT_BUILDER; + public static final String RESPONSE_DOM = "com.icesoft.domResponseDocument"; + public static final String RESPONSE_DOM_ID = "com.icesoft.domResponseDocumentID"; + public static final String OLD_DOM = "com.icesoft.oldDocument"; + public static final String RESPONSE_VIEWROOT = "com.icesoft.domResponseViewRoot"; + // Hashtable of DOMContext objects associated with each component + public static final String RESPONSE_CONTEXTS_TABLE = "com.icesoft.domResponseContexts"; + private static DocumentBuilder DOCUMENT_BUILDER; static { try { - DOCUMENT_BUILDER = - DocumentBuilderFactory.newInstance().newDocumentBuilder(); - } catch (ParserConfigurationException e) { - log.error("Cannot acquire a DocumentBuilder", e); - } } + static Unknown macro: {+ try { + DOCUMENT_BUILDER = DocumentBuilderFactory.newInstance() + .newDocumentBuilder(); + } catch (ParserConfigurationException e) { + log.error("Cannot acquire a DocumentBuilder", e); + }+ } private static boolean isStreamWritingFlag = false; private Document document; private Node cursor; private Map domResponseContexts; private Map contextServletTable; private BridgeFacesContext context; private DOMSerializer serializer; private Configuration configuration; + private static boolean isStreamWritingFlag = false; + private Document document; + private Node cursor; + private Map domResponseContexts; + private Map contextServletTable; + private BridgeFacesContext context; + private DOMSerializer serializer; + private Configuration configuration; public DOMResponseWriter(FacesContext context, DOMSerializer serializer, Configuration configuration) { this.serializer = serializer; this.configuration = configuration; try { - this.context = (BridgeFacesContext) context; - } catch (ClassCastException e) { - throw new IllegalStateException( - "ICEfaces requires the PersistentFacesServlet. " + - "Please check your web.xml servlet mappings"); - } this.initialize(); } + public DOMResponseWriter(FacesContext context, DOMSerializer serializer, + Configuration configuration) Unknown macro: {+ this.serializer = serializer;+ this.configuration = configuration;+ try { + this.context = (BridgeFacesContext) context; + } catch (ClassCastException e) { + throw new IllegalStateException( + "ICEfaces requires the PersistentFacesServlet. " + + "Please check your web.xml servlet mappings"); + }+ this.initialize();+ } Map getDomResponseContexts() { - return domResponseContexts; - } + Map getDomResponseContexts() { + return domResponseContexts; + } public Node getCursorParent() { - return cursor; - } + public Node getCursorParent() { + return cursor; + } public Document getDocument() { - return document; - } + public Document getDocument() { + return document; + } public String getContentType() { - return "text/html; charset=UTF-8"; - } + public String getContentType() { + return "text/html; charset=UTF-8"; + } public String getCharacterEncoding() { - return "UTF-8"; - } + public String getCharacterEncoding() { + return "UTF-8"; + } public void startDocument() throws IOException { - } + public void startDocument() throws IOException { + } - private void initialize() { - contextServletTable = D2DViewHandler.getContextServletTable(context); - // contexts for each component - if (contextServletTable - .containsKey(DOMResponseWriter.RESPONSE_CONTEXTS_TABLE)) { - domResponseContexts = (Map) contextServletTable - .get(DOMResponseWriter.RESPONSE_CONTEXTS_TABLE); - } - if (null == domResponseContexts) { - domResponseContexts = new HashMap(); - contextServletTable.put(DOMResponseWriter.RESPONSE_CONTEXTS_TABLE, - domResponseContexts); - } - // viewroot, application - contextServletTable.put(DOMResponseWriter.RESPONSE_VIEWROOT, - context.getViewRoot()); - cursor = document = DOCUMENT_BUILDER.newDocument(); - contextServletTable.put(DOMResponseWriter.RESPONSE_DOM, document); - boolean streamWritingParam = "true".equalsIgnoreCase( - context.getExternalContext().getInitParameter( - DOMResponseWriter.STREAM_WRITING)); - DOMResponseWriter.isStreamWritingFlag = - Beans.isDesignTime() || streamWritingParam; - } + private void initialize() { + contextServletTable = D2DViewHandler.getContextServletTable(context); + // contexts for each component + if (contextServletTable + .containsKey(DOMResponseWriter.RESPONSE_CONTEXTS_TABLE)) { + domResponseContexts = (Map) contextServletTable + .get(DOMResponseWriter.RESPONSE_CONTEXTS_TABLE); + } + if (null == domResponseContexts) { + domResponseContexts = new HashMap(); + contextServletTable.put(DOMResponseWriter.RESPONSE_CONTEXTS_TABLE, + domResponseContexts); + } + // viewroot, application + contextServletTable.put(DOMResponseWriter.RESPONSE_VIEWROOT, context + .getViewRoot()); + cursor = document = DOCUMENT_BUILDER.newDocument(); + contextServletTable.put(DOMResponseWriter.RESPONSE_DOM, document); + boolean streamWritingParam = "true".equalsIgnoreCase(context + .getExternalContext().getInitParameter( + DOMResponseWriter.STREAM_WRITING)); + DOMResponseWriter.isStreamWritingFlag = Beans.isDesignTime() + || streamWritingParam; + } - public void endDocument() throws IOException { - if (!isStreamWriting()) { - enhanceAndFixDocument(); - serializer.serialize(document); - } - } + public void endDocument() throws IOException { + if (!isStreamWriting()) { + enhanceAndFixDocument(); + serializer.serialize(document); + } + } - public void flush() throws IOException { - } + public void flush() throws IOException { + } - public void startElement(String name, UIComponent componentForElement) - throws IOException { - Node oldCursor = cursor; - Element elem = document.createElement(name); - cursor = cursor.appendChild(elem); - if (log.isTraceEnabled()) { - log.trace("startElement() name: " + name + " elem: " + elem + - " oldCursor: " + oldCursor + " newCursor: " + cursor); - } - } + public void startElement(String name, UIComponent componentForElement) + throws IOException { + Node oldCursor = cursor; + Element elem = document.createElement(name); + if (log.isTraceEnabled()) { + log.trace("attempting startElement() name: " + name + " elem: " + + elem + " oldCursor: " + oldCursor); + } + cursor = cursor.appendChild(elem); + if (log.isTraceEnabled()) { + log.trace("startElement() newCursor: " + cursor); + } + } - public void endElement(String name) throws IOException { - Node oldCursor = cursor; - cursor = cursor.getParentNode(); - if (log.isTraceEnabled()) { - log.trace("endElement() name: " + name + " oldCursor: " + - oldCursor + " newCursor: " + cursor); - } - } + public void endElement(String name) throws IOException { + Node oldCursor = cursor; + cursor = cursor.getParentNode(); + if (log.isTraceEnabled()) { + log.trace("endElement() name: " + name + " oldCursor: " + + oldCursor + " newCursor: " + cursor); + } + } - public void writeAttribute(String name, Object value, - String componentPropertyName) - throws IOException { - //name.trim() because cardemo had a leading space in an attribute name - //which made the DOM processor choke - ((Element) cursor).setAttribute(name.trim(), String.valueOf(value)); - } + public void writeAttribute(String name, Object value, + String componentPropertyName) throws IOException { + // name.trim() because cardemo had a leading space in an attribute name + // which made the DOM processor choke + ((Element) cursor).setAttribute(name.trim(), String.valueOf(value)); + } - public void writeURIAttribute(String name, Object value, - String componentPropertyName) - throws IOException { - String stringValue = String.valueOf(value); - if (stringValue.startsWith("javascript:")) { - ((Element) cursor).setAttribute(name, stringValue); - } else { - ((Element) cursor) - .setAttribute(name, stringValue.replace(' ', '+')); - } - } + public void writeURIAttribute(String name, Object value, + String componentPropertyName) throws IOException { + String stringValue = String.valueOf(value); + if (stringValue.startsWith("javascript:")) { + ((Element) cursor).setAttribute(name, stringValue); + } else { + ((Element) cursor) + .setAttribute(name, stringValue.replace(' ', '+')); + } + } - public void writeComment(Object comment) throws IOException { - if (log.isTraceEnabled()) { - log.trace("writeComment() comment: " + comment); - } - cursor.appendChild(document.createComment(String.valueOf(comment))); - } + public void writeComment(Object comment) throws IOException { + if (log.isTraceEnabled()) { + log.trace("writeComment() comment: " + comment); + } + cursor.appendChild(document.createComment(String.valueOf(comment))); + } - public void writeText(Object text, String componentPropertyName) - throws IOException { - if (log.isTraceEnabled()) { - log.trace("writeText(O,S) text: " + text); - } - cursor.appendChild(document.createTextNode(String.valueOf(text))); - } + public void writeText(Object text, String componentPropertyName) + throws IOException { + if (log.isTraceEnabled()) { + log.trace("writeText(O,S) text: " + text); + } + cursor.appendChild(document.createTextNode(String.valueOf(text))); + } - public void writeText(char text[], int off, int len) throws IOException { - if (log.isTraceEnabled()) { - log.trace("writeText(c[],i,i) text: " + - (new String(text, off, len))); - } - cursor.appendChild(document.createTextNode(new String(text, off, len))); - } + public void writeText(char text[], int off, int len) throws IOException { + if (log.isTraceEnabled()) { + log.trace("writeText(c[],i,i) text: " + + (new String(text, off, len))); + } + cursor.appendChild(document.createTextNode(new String(text, off, len))); + } - public ResponseWriter cloneWithWriter(Writer writer) { - //FIXME: This is a hack for DOM rendering but JSF currently clones the writer - //just as the components are complete - if (null != document) { - try { - endDocument(); - } catch (IOException e) { - throw new IllegalStateException(e.toString()); - } - } - try { - return new DOMResponseWriter(context, serializer, configuration); - } catch (FacesException e) { - throw new IllegalStateException(); - } - } + public ResponseWriter cloneWithWriter(Writer writer) { + // FIXME: This is a hack for DOM rendering but JSF currently clones the + // writer + // just as the components are complete + if (null != document) { + try { + endDocument(); + } catch (IOException e) { + throw new IllegalStateException(e.toString()); + } + } + try { + return new DOMResponseWriter(context, serializer, configuration); + } catch (FacesException e) { + throw new IllegalStateException(); + } + } - public void close() throws IOException { - } + public void close() throws IOException { + } public void write(char[] cbuf, int off, int len) throws IOException { if (log.isTraceEnabled()) { - log.trace("writeText(c[],i,i) str: " + - (new String(cbuf, off, len))); - } cursor.appendChild(document.createTextNode(new String(cbuf, off, len))); } + public void write(char[] cbuf, int off, int len) throws IOException Unknown macro: {+ if (log.isTraceEnabled()) { + log.trace("writeText(c[],i,i) str: " + + (new String(cbuf, off, len))); + }+ cursor.appendChild(document.createTextNode(new String(cbuf, off, len)));+ } public void write(int c) throws IOException { if (log.isTraceEnabled()) { - log.trace("write(i) hex: " + Integer.toHexString(c) + - " decimal: " + c); - } cursor.appendChild(document.createTextNode(String.valueOf((char) c))); } + public void write(int c) throws IOException Unknown macro: {+ if (log.isTraceEnabled()) { + log.trace("write(i) hex: " + Integer.toHexString(c) + + " decimal: " + c); + }+ cursor.appendChild(document.createTextNode(String.valueOf((char) c)));+ } public void write(String str) throws IOException { if (log.isTraceEnabled()) { - log.trace("write(S) str: " + str); - } cursor.appendChild(document.createTextNode(str)); } + public void write(String str) throws IOException Unknown macro: {+ if (log.isTraceEnabled()) { + log.trace("write(S) str: " + str); + }+ cursor.appendChild(document.createTextNode(str));+ } public void write(String str, int off, int len) throws IOException { if (log.isTraceEnabled()) { - log.trace("write(S,i,i) str_sub: " + str.substring(off, len)); - } cursor.appendChild(document.createTextNode(str.substring(off, len))); } + public void write(String str, int off, int len) throws IOException Unknown macro: {+ if (log.isTraceEnabled()) { + log.trace("write(S,i,i) str_sub: " + str.substring(off, len)); + }+ cursor.appendChild(document.createTextNode(str.substring(off, len)));+ } private void enhanceAndFixDocument() { Element html = (Element) document.getDocumentElement(); enhanceHtml(html = "html".equals(html.getTagName()) ? html : fixHtml()); + private void enhanceAndFixDocument() { + Element html = (Element) document.getDocumentElement(); + enhanceHtml(html = "html".equals(html.getTagName()) ? html : fixHtml()); - Element head = (Element) document.getElementsByTagName("head").item(0); - enhanceHead(head == null ? fixHead() : head); + Element head = (Element) document.getElementsByTagName("head").item(0); + enhanceHead(head == null ? fixHead() : head); - Element body = (Element) document.getElementsByTagName("body").item(0); - enhanceBody(body == null ? fixBody() : body); - } + Element body = (Element) document.getElementsByTagName("body").item(0); + enhanceBody(body == null ? fixBody() : body); + } private void enhanceHtml(Element html) { - //add lang attribute - Locale locale = context.getApplication().getViewHandler().calculateLocale(context); - html.setAttribute("lang", locale.getLanguage()); - } + private void enhanceHtml(Element html) { + // add lang attribute + Locale locale = context.getApplication().getViewHandler() + .calculateLocale(context); + html.setAttribute("lang", locale.getLanguage()); + } private void enhanceBody(Element body) { //id required for forwarded (server-side) redirects body.setAttribute("id", "body"); Element iframe = document.createElement("iframe"); body.insertBefore(iframe, body.getFirstChild()); iframe.setAttribute("id", "history-frame"); Object request = context.getExternalContext().getRequest(); + private void enhanceBody(Element body) { + // id required for forwarded (server-side) redirects + body.setAttribute("id", "body"); + Element iframe = document.createElement("iframe"); + body.insertBefore(iframe, body.getFirstChild()); + iframe.setAttribute("id", "history-frame"); + Object request = context.getExternalContext().getRequest(); final String frameURI; //another "workaround" to resolve the iframe URI @@ -337,150 +338,185 @@ iframe.setAttribute("style", "z-index: 10000; visibility: hidden; width: 0; height: 0; position: absolute; opacity: 0.22; filter: alpha(opacity=22);"); // TODO This is only meant to be a transitional focus retention(management) solution. String focusId = context.getFocusId(); if (focusId != null && !focusId.equals("null")) { - JavascriptContext.focus(context, focusId); - } + // TODO This is only meant to be a transitional focus + // retention(management) solution. + String focusId = context.getFocusId(); + if (focusId != null && !focusId.equals("null")) { + JavascriptContext.focus(context, focusId); + } Element script = (Element) body.appendChild(document.createElement("script")); script.setAttribute("id", JavascriptContext.DYNAMIC_CODE_ID); script.setAttribute("language", "javascript"); String calls = JavascriptContext.getJavascriptCalls(context); script.appendChild(document.createTextNode(calls)); + Element script = (Element) body.appendChild(document + .createElement("script")); + script.setAttribute("id", JavascriptContext.DYNAMIC_CODE_ID); + script.setAttribute("language", "javascript"); + String calls = JavascriptContext.getJavascriptCalls(context); + script.appendChild(document.createTextNode(calls)); Map session = context.getExternalContext().getSessionMap(); ElementController.from(session).addInto(body); + Map session = context.getExternalContext().getSessionMap(); + ElementController.from(session).addInto(body); String sessionIDScript = "window.session='" + context.getIceFacesId() + "';\n"; //add viewIdentifier property to the container element ("body" for servlet env., any element for the portlet env.) String viewIDScript = "document.getElementById('configuration-script').parentNode.viewIdentifier=" + context.getViewNumber() + ";\n"; String viewsIDScript = "if (!window.views) window.views = []; window.views.push(" + context.getViewNumber() + ");\n"; + String sessionIDScript = "window.session='" + context.getIceFacesId() + + "';\n"; + // add viewIdentifier property to the container element ("body" for + // servlet env., any element for the portlet env.) + String viewIDScript = "document.getElementById('configuration-script').parentNode.viewIdentifier=" + + context.getViewNumber() + ";\n"; + String viewsIDScript = "if (!window.views) window.views = []; window.views.push(" + + context.getViewNumber() + ");\n"; String configurationScript = "window.configuration = {" + "synchronous: " + configuration.getAttribute("synchronousUpdate", "false") + "," + "redirectURI: " + configuration.getAttribute("connectionLostRedirectURI", "null") + "," + "connection: {" + "context: '" + context.getApplication().getViewHandler().getResourceURL(context, "/") + "'," + "timeout: " + configuration.getAttributeAsLong("connectionTimeout", 30000) + "," + "heartbeat: {" + - "interval: " + configuration.getAttributeAsLong("heartbeatInterval", 20000) + "," + - "timeout: " + configuration.getAttributeAsLong("heartbeatTimeout", 3000) + "," + - "retries: " + configuration.getAttributeAsLong("heartbeatRetries", 3) + - "} " + "}" + "};\n"; + String configurationScript = "window.configuration = {" + + "synchronous: " + + configuration.getAttribute("synchronousUpdate", "false") + + "," + + "redirectURI: " + + configuration.getAttribute("connectionLostRedirectURI", + "null") + + "," + + "connection: Unknown macro: {"+ + "context} " + "};\n"; Element configurationElement = (Element) body.appendChild(document.createElement("script")); configurationElement.setAttribute("id", "configuration-script"); configurationElement.setAttribute("language", "javascript"); configurationElement.appendChild(document.createTextNode(sessionIDScript + viewIDScript + viewsIDScript + configurationScript)); body.appendChild(configurationElement); } + Element configurationElement = (Element) body.appendChild(document + .createElement("script")); + configurationElement.setAttribute("id", "configuration-script"); + configurationElement.setAttribute("language", "javascript"); + configurationElement.appendChild(document + .createTextNode(sessionIDScript + viewIDScript + viewsIDScript + + configurationScript)); + body.appendChild(configurationElement); + } private void enhanceHead(Element head) { ViewHandler handler = context.getApplication().getViewHandler(); //id required for forwarded (server-side) redirects head.setAttribute("id", "head"); Element meta = (Element) head.appendChild(document.createElement("meta")); meta.setAttribute("name", "icefaces"); meta.setAttribute("content", "Rendered by ICEFaces D2D"); + private void addNoScriptIfNotAlreadyAdded(Element head) Unknown macro: {+ + NodeList list = head.getElementsByTagName("noscript");+ if( list.getLength() == 0 ){ + Element noscript = (Element) head.appendChild(document + .createElement("noscript")); + Element noscriptMeta = (Element) noscript.appendChild(document + .createElement("meta")); + noscriptMeta.setAttribute("http-equiv", "refresh"); + noscriptMeta.setAttribute("content", "0;url=" + + context.getApplication().getViewHandler().getResourceURL( + context, "/xmlhttp/javascript-blocked")); + }+ } Element noscript = (Element) head.appendChild(document.createElement("noscript")); Element noscriptMeta = (Element) noscript.appendChild(document.createElement("meta")); noscriptMeta.setAttribute("http-equiv", "refresh"); noscriptMeta .setAttribute("content", "0;url=" + handler.getResourceURL(context, "/xmlhttp/javascript-blocked")); + private void enhanceHead(Element head) { + ViewHandler handler = context.getApplication().getViewHandler(); + // id required for forwarded (server-side) redirects + head.setAttribute("id", "head"); + Element meta = (Element) head.appendChild(document + .createElement("meta")); + meta.setAttribute("name", "icefaces"); + meta.setAttribute("content", "Rendered by ICEFaces D2D"); //load libraries Collection libs = new ArrayList(); if (context.getExternalContext().getInitParameter(D2DViewHandler.INCLUDE_OPEN_AJAX_HUB) != null) { - libs.add("/xmlhttp/openajax.js"); - } libs.add("/xmlhttp" + StartupTime.getStartupInc() + "icefaces-d2d.js"); //todo: refactor how extral libraries are loaded into the bridge; always include extra libraries for now libs.add("/xmlhttp" + StartupTime.getStartupInc() + "ice-extras.js"); if (context.getExternalContext().getRequestMap().get(Constants.INC_SERVLET_PATH) == null) { String[] componentLibs = JavascriptContext.getIncludedLibs(context); for (int i = 0; i < componentLibs.length; i++) { String componentLib = componentLibs [i] ; if (!libs.contains(componentLib)) { - libs.add(componentLib); - } } } + addNoScriptIfNotAlreadyAdded(head); Iterator iterator = libs.iterator(); while (iterator.hasNext()) { - String lib = (String) iterator.next(); - Element script = (Element) head - .appendChild(document.createElement("script")); - script.setAttribute("language", "javascript"); - script.setAttribute("src", handler.getResourceURL(context, lib)); - } + // load libraries + Collection libs = new ArrayList(); + if (context.getExternalContext().getInitParameter( + D2DViewHandler.INCLUDE_OPEN_AJAX_HUB) != null) { + libs.add("/xmlhttp/openajax.js"); + } + libs.add("/xmlhttp" + StartupTime.getStartupInc() + "icefaces-d2d.js"); + // todo: refactor how extral libraries are loaded into the bridge; + // always include extra libraries for now + libs.add("/xmlhttp" + StartupTime.getStartupInc() + "ice-extras.js"); + if (context.getExternalContext().getRequestMap().get( + Constants.INC_SERVLET_PATH) == null) { + String[] componentLibs = JavascriptContext.getIncludedLibs(context); + for (int i = 0; i < componentLibs.length; i++) Unknown macro: {+ String componentLib = componentLibs[i];+ if (!libs.contains(componentLib)) { + libs.add(componentLib); + }+ } + } String sessionIdentifier = context.getIceFacesId(); Element viewAndSessionScript = (Element) head.appendChild(document.createElement("script")); viewAndSessionScript.setAttribute("language", "javascript"); viewAndSessionScript.appendChild(document.createTextNode( "window.session = '" + sessionIdentifier + "';" )); } + Iterator iterator = libs.iterator(); + while (iterator.hasNext()) { + String lib = (String) iterator.next(); + Element script = (Element) head.appendChild(document + .createElement("script")); + script.setAttribute("language", "javascript"); + script.setAttribute("src", handler.getResourceURL(context, lib)); + } private Element fixHtml() { - Element root = document.getDocumentElement(); - Element html = document.createElement("html"); - document.replaceChild(html, root); - html.appendChild(root); + String sessionIdentifier = context.getIceFacesId(); + Element viewAndSessionScript = (Element) head.appendChild(document + .createElement("script")); + viewAndSessionScript.setAttribute("language", "javascript"); + viewAndSessionScript + .appendChild(document.createTextNode("window.session = '" + + sessionIdentifier + "';")); + } return html; } + private Element fixHtml() { + Element root = document.getDocumentElement(); + Element html = document.createElement("html"); + document.replaceChild(html, root); + html.appendChild(root); private Element fixBody() { Element html = document.getDocumentElement(); Element body = document.createElement("body"); NodeList children = html.getChildNodes(); int length = children.getLength(); Node[] nodes = new Node [length] ; //copy the children first, since NodeList is live for (int i = 0; i < nodes.length; i++) nodes [i] = children.item ; for (int i = 0; i < nodes.length; i++) { - Node node = nodes[i]; - if (!(node instanceof Element && - "head".equals(((Element) node).getTagName()))) - body.appendChild(node); - } html.appendChild(body); + return html; + } return body; } + private Element fixBody() { + Element html = document.getDocumentElement(); + Element body = document.createElement("body"); + NodeList children = html.getChildNodes(); + int length = children.getLength(); + Node[] nodes = new Node [length] ; + // copy the children first, since NodeList is live + for (int i = 0; i < nodes.length; i++) + nodes [i] = children.item ; + for (int i = 0; i < nodes.length; i++) { + Node node = nodes[i]; + if (!(node instanceof Element && "head".equals(((Element) node) + .getTagName()))) + body.appendChild(node); + } + html.appendChild(body); private Element fixHead() { - Element html = document.getDocumentElement(); - Element head = document.createElement("head"); - html.insertBefore(head, html.getFirstChild()); + return body; + } return head; } + private Element fixHead() { + Element html = document.getDocumentElement(); + Element head = document.createElement("head"); + html.insertBefore(head, html.getFirstChild()); /** * This method sets the write cursor for DOM modifications. Subsequent DOM * modifications will take place below the cursor element. * * @param cursorParent parent node for subsequent modifications to the DOM */ protected void setCursorParent(Node cursorParent) { - this.cursor = cursorParent; - } + return head; + } public static boolean isStreamWriting() { - return isStreamWritingFlag; - } + /** + * This method sets the write cursor for DOM modifications. Subsequent DOM + * modifications will take place below the cursor element. + * + * @param cursorParent + * parent node for subsequent modifications to the DOM + */ + protected void setCursorParent(Node cursorParent) { + this.cursor = cursorParent; + } + public static boolean isStreamWriting() { + return isStreamWritingFlag; + } }
        Hide
        Mircea Toma added a comment -

        Set thread locals.

        Show
        Mircea Toma added a comment - Set thread locals.

          People

          • Assignee:
            Unassigned
            Reporter:
            Philip Breau
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: