myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lof...@apache.org
Subject svn commit: r917990 - in /myfaces/tobago/trunk: core/src/main/java/org/apache/myfaces/tobago/internal/context/ core/src/test/java/org/apache/myfaces/tobago/internal/context/ theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarb...
Date Tue, 02 Mar 2010 12:18:05 GMT
Author: lofwyr
Date: Tue Mar  2 12:18:04 2010
New Revision: 917990

URL: http://svn.apache.org/viewvc?rev=917990&view=rev
Log:
TOBAGO-846: ResponseWriterDivider
 - Is is also required to have more than one ResponseWriterDivider on a single page, because
the Menu and the TreeListbox uses it. For that the name of the ResponseWriterDivider in the
request map must be configurable.

Modified:
    myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/internal/context/ResponseWriterDivider.java
    myfaces/tobago/trunk/core/src/test/java/org/apache/myfaces/tobago/internal/context/ResponseWriterDividerUnitTest.java
    myfaces/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/TreeListboxRenderer.java
    myfaces/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/TreeNodeRenderer.java

Modified: myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/internal/context/ResponseWriterDivider.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/internal/context/ResponseWriterDivider.java?rev=917990&r1=917989&r2=917990&view=diff
==============================================================================
--- myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/internal/context/ResponseWriterDivider.java
(original)
+++ myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/internal/context/ResponseWriterDivider.java
Tue Mar  2 12:18:04 2010
@@ -29,28 +29,30 @@
 import java.util.Map;
 
 /**
- * Sometimes the rendered output must be places in the Response in a different order than
it was rendered.
+ * In some cases the rendered output must be places in the Response in a different order
than it was rendered.
  * The <code>ResponseWriterDivider</code> helps to manage a list of buffers which
holds the temporary output.
  */
 public class ResponseWriterDivider {
 
   private static final Log LOG = LogFactory.getLog(ResponseWriterDivider.class);
 
-  private static final String NAME_IN_REQUEST = ResponseWriterDivider.class.getName();
-
   private List<ResponseWriter> writers;
   private List<FastStringWriter> buffers;
   
   private ResponseWriter original;
   
   private int current;
+  
+  private String nameInRequest;
 
-  public static ResponseWriterDivider getInstance(FacesContext facesContext) {
+  public static ResponseWriterDivider getInstance(FacesContext facesContext, String nameInRequest)
{
     final Map<String,Object> map = facesContext.getExternalContext().getRequestMap();
-    ResponseWriterDivider divider = (ResponseWriterDivider) map.get(NAME_IN_REQUEST);
+    ResponseWriterDivider divider = (ResponseWriterDivider) map.get(nameInRequest);
     if (divider == null) {
       divider = new ResponseWriterDivider(facesContext);
-      map.put(NAME_IN_REQUEST, divider);
+      map.put(nameInRequest, divider);
+      divider.nameInRequest = nameInRequest;
+      
     }
     return divider;
   }
@@ -65,6 +67,8 @@
   /**
    * Create (if needed) and activate a new branch. 
    * After this call, all output will be stored in this new branch. 
+   * <p>
+   * It is usually needed to get the response writer again with HtmlRendererUtils.getTobagoResponseWriter();
    * @return true if the branch was not created new. So the branch was already existent.
    */
   public boolean activateBranch(FacesContext facesContext) {
@@ -90,6 +94,8 @@
   /**
    * Passivate the current branch. 
    * After this call, all output will be written in the former branch (if any) or into the
original writer.
+   * <p>
+   * It is usually needed to get the response writer again with HtmlRendererUtils.getTobagoResponseWriter();
    * @return true, if the current writer is not the original writer. So the "stack" is at
the bottom. 
    */
   public boolean passivateBranch(FacesContext facesContext) {
@@ -116,14 +122,14 @@
    * Write the collected stuff in the original writer.
    * This is always the last call on this object.
    */
-  public void writeOut(FacesContext facesContext) throws IOException {
+  public void writeOutAndCleanUp(FacesContext facesContext) throws IOException {
     facesContext.setResponseWriter(original);
     for (FastStringWriter buffer : buffers) {
       original.write(buffer.toString());
     }
     // clean up.
-    writers = null;
-    buffers = null;
+    final Map<String,Object> map = facesContext.getExternalContext().getRequestMap();
+    map.remove(nameInRequest);
   }
 
   @Override

Modified: myfaces/tobago/trunk/core/src/test/java/org/apache/myfaces/tobago/internal/context/ResponseWriterDividerUnitTest.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/core/src/test/java/org/apache/myfaces/tobago/internal/context/ResponseWriterDividerUnitTest.java?rev=917990&r1=917989&r2=917990&view=diff
==============================================================================
--- myfaces/tobago/trunk/core/src/test/java/org/apache/myfaces/tobago/internal/context/ResponseWriterDividerUnitTest.java
(original)
+++ myfaces/tobago/trunk/core/src/test/java/org/apache/myfaces/tobago/internal/context/ResponseWriterDividerUnitTest.java
Tue Mar  2 12:18:04 2010
@@ -57,8 +57,8 @@
 
     render(facesContext, root);
 
-    ResponseWriterDivider divider = ResponseWriterDivider.getInstance(facesContext);
-    divider.writeOut(facesContext);
+    ResponseWriterDivider divider = ResponseWriterDivider.getInstance(facesContext, "unit
test");
+    divider.writeOutAndCleanUp(facesContext);
 
     String expected 
         = "(Root)\n"
@@ -82,7 +82,7 @@
   }
 
   private void render(FacesContext facesContext, DefaultMutableTreeNode node) throws IOException
{
-    ResponseWriterDivider divider = ResponseWriterDivider.getInstance(facesContext);
+    ResponseWriterDivider divider = ResponseWriterDivider.getInstance(facesContext, "unit
test");
 
     String label = (String) node.getUserObject();
 

Modified: myfaces/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/TreeListboxRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/TreeListboxRenderer.java?rev=917990&r1=917989&r2=917990&view=diff
==============================================================================
--- myfaces/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/TreeListboxRenderer.java
(original)
+++ myfaces/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/TreeListboxRenderer.java
Tue Mar  2 12:18:04 2010
@@ -40,6 +40,8 @@
 public class TreeListboxRenderer extends LayoutComponentRendererBase {
 
   private static final String SCRIPT = "script/tobago-tree.js";
+  
+  public static final String DIVIDER = TreeListboxRenderer.class.getName() + "DIVIDER";
 
   public void prepareRender(FacesContext facesContext, UIComponent component) throws IOException
{
     super.prepareRender(facesContext, component);
@@ -118,7 +120,7 @@
     scrollDivStyle.setPosition(Position.ABSOLUTE);
     writer.writeStyleAttribute(scrollDivStyle);
     
-    ResponseWriterDivider divider = ResponseWriterDivider.getInstance(facesContext);
+    ResponseWriterDivider divider = ResponseWriterDivider.getInstance(facesContext, DIVIDER);
     // write in all open branches the end tag.
     while (divider.activateBranch(facesContext)) {
       writer = HtmlRendererUtils.getTobagoResponseWriter(facesContext);
@@ -127,7 +129,7 @@
     while (divider.passivateBranch(facesContext)) {
     }  
       
-    divider.writeOut(facesContext);
+    divider.writeOutAndCleanUp(facesContext);
 
     writer = HtmlRendererUtils.getTobagoResponseWriter(facesContext);
 

Modified: myfaces/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/TreeNodeRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/TreeNodeRenderer.java?rev=917990&r1=917989&r2=917990&view=diff
==============================================================================
--- myfaces/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/TreeNodeRenderer.java
(original)
+++ myfaces/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/TreeNodeRenderer.java
Tue Mar  2 12:18:04 2010
@@ -140,8 +140,8 @@
 
     if (folder) {
       boolean siblingMode = "siblingLeafOnly".equals(tree.getAttributes().get(Attributes.SELECTABLE));
-
-      boolean alreadyExists = ResponseWriterDivider.getInstance(facesContext).activateBranch(facesContext);
+      ResponseWriterDivider divider = ResponseWriterDivider.getInstance(facesContext, TreeListboxRenderer.DIVIDER);
+      boolean alreadyExists = divider.activateBranch(facesContext);
       writer = HtmlRendererUtils.getTobagoResponseWriter(facesContext);
       if (!alreadyExists) {
         writer.startElement(HtmlConstants.DIV, null);
@@ -484,10 +484,11 @@
   protected void encodeEndListbox(FacesContext facesContext, UITreeNode node) throws IOException
{
     boolean folder = node.isFolder();
     if (folder) {
-      TobagoResponseWriterImpl writer = (TobagoResponseWriterImpl) HtmlRendererUtils.getTobagoResponseWriter(facesContext);
+      TobagoResponseWriterImpl writer 
+          = (TobagoResponseWriterImpl) HtmlRendererUtils.getTobagoResponseWriter(facesContext);
       writer.endElement(HtmlConstants.SELECT);
-
-      ResponseWriterDivider.getInstance(facesContext).passivateBranch(facesContext);
+      ResponseWriterDivider divider = ResponseWriterDivider.getInstance(facesContext, TreeListboxRenderer.DIVIDER);
+      divider.passivateBranch(facesContext);
     }
   }
 



Mime
View raw message