[seam-commits] Seam SVN: r9335 - in trunk/src/debug: META-INF and 4 other directories.

seam-commits at lists.jboss.org seam-commits at lists.jboss.org
Wed Oct 15 04:54:23 EDT 2008


Author: dan.j.allen
Date: 2008-10-15 04:54:22 -0400 (Wed, 15 Oct 2008)
New Revision: 9335

Added:
   trunk/src/debug/com/
   trunk/src/debug/com/sun/
   trunk/src/debug/com/sun/facelets/
   trunk/src/debug/com/sun/facelets/StateWriterControl.java
   trunk/src/debug/org/jboss/seam/debug/jsf/DebugRedirect.java
Modified:
   trunk/src/debug/META-INF/debug.xhtml
   trunk/src/debug/org/jboss/seam/debug/jsf/SeamDebugPhaseListener.java
Log:
Add logic to write state into response to support forms on debug page
Create a special redirect component for managing the redirect away from destroying a conversation
don't use qualified names for imported built-in components


Modified: trunk/src/debug/META-INF/debug.xhtml
===================================================================
--- trunk/src/debug/META-INF/debug.xhtml	2008-10-15 07:16:01 UTC (rev 9334)
+++ trunk/src/debug/META-INF/debug.xhtml	2008-10-15 08:54:22 UTC (rev 9335)
@@ -104,12 +104,11 @@
           <f:facet name="header">Action</f:facet>
           <h:outputLink>
             Select
-            <f:param name="#{org.jboss.seam.core.manager.conversationIdParameter}" value="#{_entry.id}"/>
+            <f:param name="#{manager.conversationIdParameter}" value="#{_entry.id}"/>
           </h:outputLink>
           #{' '}
-          <h:commandLink actionListener="#{_entry.destroy}" action="#{org.jboss.seam.faces.redirect.execute}" value="Destroy">
-            <f:setPropertyActionListener target="#{org.jboss.seam.faces.redirect.conversationPropagationEnabled}" value="#{false}"/>
-            <f:setPropertyActionListener target="#{org.jboss.seam.faces.redirect.viewId}" value="#{view.viewId}"/>
+          <h:commandLink actionListener="#{_entry.destroy}" action="#{org.jboss.seam.debug.jsf.debugRedirect.execute}" value="Destroy">
+            <f:setPropertyActionListener target="#{org.jboss.seam.debug.jsf.debugRedirect.viewId}" value="#{view.viewId}"/>
           </h:commandLink>
         </h:column>
       </h:dataTable>
@@ -146,10 +145,10 @@
         <span id="conversationContextOff" style="display: none;">+</span>
         <span id="conversationContextOn">-</span>
         &#160;Conversation Context&#160;
-        <h:outputText value="(#{org.jboss.seam.core.manager.currentConversationId})"
-                      rendered="#{org.jboss.seam.core.manager.longRunningConversation}"/>
+        <h:outputText value="(#{manager.currentConversationId})"
+                      rendered="#{manager.longRunningConversation}"/>
         <h:outputText value="(None selected)"
-                      rendered="#{!org.jboss.seam.core.manager.longRunningConversation}"/>
+                      rendered="#{!manager.longRunningConversation}"/>
       </a>
     </h2>
     <div id="conversationContext">
@@ -161,7 +160,7 @@
         <h:outputLink>
           #{name}
           <f:param name="name" value="#{name}"/>
-          <f:param name="#{org.jboss.seam.core.manager.conversationIdParameter}" value="#{conversation.id}"/>
+          <f:param name="#{manager.conversationIdParameter}" value="#{conversation.id}"/>
         </h:outputLink>
       </h:column>
     </h:dataTable>
@@ -183,7 +182,7 @@
         <h:outputLink>
           #{name}
           <f:param name="name" value="#{name}"/>
-          <f:param name="#{org.jboss.seam.core.manager.conversationIdParameter}" value="#{conversation.id}"/>
+          <f:param name="#{manager.conversationIdParameter}" value="#{conversation.id}"/>
         </h:outputLink>
       </h:column>
     </h:dataTable>
@@ -205,7 +204,7 @@
         <h:outputLink>
           #{name}
           <f:param name="name" value="#{name}"/>
-          <f:param name="#{org.jboss.seam.core.manager.conversationIdParameter}" value="#{conversation.id}"/>
+          <f:param name="#{manager.conversationIdParameter}" value="#{conversation.id}"/>
         </h:outputLink>
       </h:column>
     </h:dataTable>
@@ -225,7 +224,7 @@
         <h:outputLink>
           #{name}
           <f:param name="name" value="#{name}"/>
-          <f:param name="#{org.jboss.seam.core.manager.conversationIdParameter}" value="#{conversation.id}"/>
+          <f:param name="#{manager.conversationIdParameter}" value="#{conversation.id}"/>
         </h:outputLink>
       </h:column>
     </h:dataTable>

Added: trunk/src/debug/com/sun/facelets/StateWriterControl.java
===================================================================
--- trunk/src/debug/com/sun/facelets/StateWriterControl.java	                        (rev 0)
+++ trunk/src/debug/com/sun/facelets/StateWriterControl.java	2008-10-15 08:54:22 UTC (rev 9335)
@@ -0,0 +1,36 @@
+package com.sun.facelets;
+
+import java.io.Writer;
+
+import javax.faces.context.ResponseWriter;
+
+/**
+ * This is a hack to instantiate a thread-local object that Facelets uses to
+ * write the STATE_KEY into the response when directed by JSF. The STATE_KEY is
+ * written in the case when there is a form on the page. This hack is necessary
+ * since we are not calling Facelets in the normal way (and hence it is not
+ * completely initialized).
+ */
+public class StateWriterControl
+{
+   public static void initialize(Writer writer)
+   {
+      new StateWriter(writer, 1024);
+   }
+   
+   public static ResponseWriter createClone(ResponseWriter writer) {
+      return writer.cloneWithWriter(StateWriter.getCurrentInstance());
+   }
+   
+   public static boolean isStateWritten() {
+      return StateWriter.getCurrentInstance().isStateWritten();
+   }
+   
+   public static String getAndResetBuffer() {
+      return StateWriter.getCurrentInstance().getAndResetBuffer();
+   }
+   
+   public static void release() {
+      StateWriter.getCurrentInstance().release();
+   }
+}

Added: trunk/src/debug/org/jboss/seam/debug/jsf/DebugRedirect.java
===================================================================
--- trunk/src/debug/org/jboss/seam/debug/jsf/DebugRedirect.java	                        (rev 0)
+++ trunk/src/debug/org/jboss/seam/debug/jsf/DebugRedirect.java	2008-10-15 08:54:22 UTC (rev 9335)
@@ -0,0 +1,31 @@
+package org.jboss.seam.debug.jsf;
+
+import static org.jboss.seam.annotations.Install.BUILT_IN;
+
+import org.jboss.seam.annotations.Install;
+import org.jboss.seam.annotations.Name;
+import org.jboss.seam.annotations.intercept.BypassInterceptors;
+import org.jboss.seam.faces.FacesManager;
+
+ at Name("org.jboss.seam.debug.jsf.debugRedirect")
+ at BypassInterceptors
+ at Install(debug = true, precedence = BUILT_IN, classDependencies = "javax.faces.context.FacesContext")
+public class DebugRedirect
+{
+   private String viewId;
+
+   public String getViewId()
+   {
+      return viewId;
+   }
+
+   public void setViewId(String viewId)
+   {
+      this.viewId = viewId;
+   }
+
+   public void execute()
+   {
+      FacesManager.instance().redirect(viewId, null, false);
+   }
+}

Modified: trunk/src/debug/org/jboss/seam/debug/jsf/SeamDebugPhaseListener.java
===================================================================
--- trunk/src/debug/org/jboss/seam/debug/jsf/SeamDebugPhaseListener.java	2008-10-15 07:16:01 UTC (rev 9334)
+++ trunk/src/debug/org/jboss/seam/debug/jsf/SeamDebugPhaseListener.java	2008-10-15 08:54:22 UTC (rev 9335)
@@ -1,8 +1,10 @@
 package org.jboss.seam.debug.jsf;
 
 import java.io.IOException;
+import java.io.Writer;
 import java.net.URL;
 
+import javax.faces.application.StateManager;
 import javax.faces.component.UIViewRoot;
 import javax.faces.context.FacesContext;
 import javax.faces.context.ResponseWriter;
@@ -15,10 +17,10 @@
 import org.jboss.seam.navigation.Pages;
 
 import com.sun.facelets.Facelet;
+import com.sun.facelets.StateWriterControl;
 import com.sun.facelets.compiler.SAXCompiler;
 import com.sun.facelets.impl.DefaultFaceletFactory;
 import com.sun.facelets.impl.DefaultResourceResolver;
-import com.sun.facelets.tag.jsf.ComponentSupport;
 
 /**
  * Intercepts any request for a view-id like /debug.xxx and renders
@@ -28,7 +30,8 @@
  */
 public class SeamDebugPhaseListener implements PhaseListener
 {
-
+   private static final String STATE_KEY = "~facelets.VIEW_STATE~";
+   
    public void beforePhase(PhaseEvent event)
    {
       FacesLifecycle.setPhaseId( event.getPhaseId() ); //since this gets called before SeamPhaseListener!
@@ -40,16 +43,21 @@
             FacesContext facesContext = FacesContext.getCurrentInstance();
             URL url = SeamDebugPhaseListener.class.getClassLoader().getResource("META-INF/debug.xhtml");
             Facelet f = new DefaultFaceletFactory( new SAXCompiler(), new DefaultResourceResolver() ).getFacelet(url);
-            UIViewRoot root = facesContext.getViewRoot();
-            f.apply(facesContext, root);
+            UIViewRoot viewRoot = facesContext.getViewRoot();
+            f.apply(facesContext, viewRoot);
             HttpServletResponse response = (HttpServletResponse) facesContext.getExternalContext().getResponse();
             response.setCharacterEncoding("UTF-8");
             response.setContentType("text/html; UTF-8"); 
-            ResponseWriter writer = facesContext.getRenderKit().createResponseWriter( response.getWriter(), "text/html", "UTF-8" );
+            ResponseWriter originalWriter = facesContext.getRenderKit().createResponseWriter( response.getWriter(), "text/html", "UTF-8" );
+            StateWriterControl.initialize(originalWriter);
+            ResponseWriter writer = StateWriterControl.createClone(originalWriter);
             facesContext.setResponseWriter(writer);
-            //root.renderAll();
-            ComponentSupport.encodeRecursive(facesContext, root);
-            writer.flush();
+            writer.startDocument();
+            viewRoot.encodeAll(facesContext);
+            writer.endDocument();
+            writer.close();
+            writeState(facesContext, originalWriter);
+            originalWriter.flush();
             facesContext.responseComplete();
          }
          catch (IOException ioe)
@@ -66,4 +74,52 @@
       return PhaseId.RENDER_RESPONSE;
    }
    
+   private void writeState(FacesContext facesContext, Writer writer) throws IOException {
+      try
+      {
+         if (StateWriterControl.isStateWritten())
+         {
+            String content = StateWriterControl.getAndResetBuffer();
+            int end = content.indexOf(STATE_KEY);
+            if (end >= 0)
+            {
+               StateManager stateMgr = facesContext.getApplication().getStateManager();
+               Object stateObj = stateMgr.saveView(facesContext);
+               String stateStr;
+               if (stateObj == null)
+               {
+                  stateStr = null;
+               }
+               else
+               {
+                  stateMgr.writeState(facesContext, stateObj);
+                  stateStr = StateWriterControl.getAndResetBuffer();
+               }
+
+               int start = 0;
+
+               while (end != -1)
+               {
+                  writer.write(content, start, end - start);
+                  if (stateStr != null)
+                  {
+                     writer.write(stateStr);
+                  }
+                  start = end + STATE_KEY.length();
+                  end = content.indexOf(STATE_KEY, start);
+               }
+               writer.write(content, start, content.length() - start);
+            }
+            else
+            {
+               writer.write(content);
+            }
+         }
+      }
+      finally
+      {
+         StateWriterControl.release();
+      }
+   }
+   
 }




More information about the seam-commits mailing list