You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by lo...@apache.org on 2006/01/17 12:12:06 UTC

svn commit: r369754 - in /incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago: component/UIGridLayout.java util/LayoutUtil.java

Author: lofwyr
Date: Tue Jan 17 03:11:58 2006
New Revision: 369754

URL: http://svn.apache.org/viewcvs?rev=369754&view=rev
Log:
bugfix: inner class Row is now temporary for rendering, so it will not be seriealized (solves bug MYFACES-914)

Modified:
    incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/component/UIGridLayout.java
    incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/util/LayoutUtil.java

Modified: incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/component/UIGridLayout.java
URL: http://svn.apache.org/viewcvs/incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/component/UIGridLayout.java?rev=369754&r1=369753&r2=369754&view=diff
==============================================================================
--- incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/component/UIGridLayout.java (original)
+++ incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/component/UIGridLayout.java Tue Jan 17 03:11:58 2006
@@ -22,7 +22,10 @@
 import org.apache.commons.lang.StringUtils;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-import static org.apache.myfaces.tobago.TobagoConstants.*;
+import static org.apache.myfaces.tobago.TobagoConstants.ATTR_COLUMNS;
+import static org.apache.myfaces.tobago.TobagoConstants.ATTR_LAYOUT_ROWS;
+import static org.apache.myfaces.tobago.TobagoConstants.ATTR_SPAN_X;
+import static org.apache.myfaces.tobago.TobagoConstants.ATTR_SPAN_Y;
 import org.apache.myfaces.tobago.util.LayoutUtil;
 
 import javax.faces.component.UIComponent;
@@ -30,13 +33,10 @@
 import java.io.IOException;
 import java.io.Serializable;
 import java.util.ArrayList;
-import java.util.Iterator;
 import java.util.List;
 
 public class UIGridLayout extends UILayout {
 
-// ///////////////////////////////////////////// constant
-
   private static final Log LOG = LogFactory.getLog(UIGridLayout.class);
 
   public static final String COMPONENT_TYPE = "org.apache.myfaces.tobago.GridLayout";
@@ -45,30 +45,29 @@
   public static final Marker FREE = new Marker("free");
   public static final String USED = "used";
 
-// ///////////////////////////////////////////// attribute
-
-// ///////////////////////////////////////////// constructor
-
-// ///////////////////////////////////////////// code
-
+  @Override
   public String getFamily() {
     return COMPONENT_FAMILY;
   }
 
   private boolean ignoreFree;
 
+  @Override
   public boolean getRendersChildren() {
     return true;
   }
 
+  @Override
   public void encodeChildren(FacesContext context)
       throws IOException {
     // do nothing here
   }
 
-  public void encodeChildrenOfComponent(FacesContext facesContext, UIComponent component) throws IOException {
-    clearRows();
+  @Override
+  public void encodeChildrenOfComponent(
+      FacesContext facesContext, UIComponent component) throws IOException {
     super.encodeChildrenOfComponent(facesContext, component);
+    clearRows();
   }
 
   private void clearRows() {
@@ -98,10 +97,10 @@
   private List<Row> createRows() {
     List<Row> rows = new ArrayList<Row>();
     int columnCount = getColumnCount();
-    List children = LayoutUtil.addChildren(new ArrayList(), getParent());
+    List<UIComponent> children
+        = LayoutUtil.addChildren(new ArrayList<UIComponent>(), getParent());
 
-    for (Iterator iterator = children.iterator(); iterator.hasNext();) {
-      UIComponent component = (UIComponent) iterator.next();
+    for (UIComponent component : children) {
       int spanX = getSpanX(component);
       int spanY = getSpanY(component);
 
@@ -109,16 +108,16 @@
       if (r == rows.size()) {
         rows.add(new Row(columnCount));
       }
-      int c = ((Row) rows.get(r)).nextFreeColumn();
-      ((Row) rows.get(r)).addControl(component, spanX);
-      ((Row) rows.get(r)).fill(c + 1, c + spanX, component.isRendered());
+      int c = rows.get(r).nextFreeColumn();
+      rows.get(r).addControl(component, spanX);
+      rows.get(r).fill(c + 1, c + spanX, component.isRendered());
 
       for (int i = r + 1; i < r + spanY; i++) {
 
         if (i == rows.size()) {
           rows.add(new Row(columnCount));
         }
-        ((Row) rows.get(i)).fill(c, c + spanX, component.isRendered());
+        rows.get(i).fill(c, c + spanX, component.isRendered());
       }
     }
     getAttributes().put(ATTR_LAYOUT_ROWS, rows);
@@ -155,7 +154,7 @@
     this.ignoreFree = ignoreFree;
   }
 
-  // ///////////////////////////////////////////////////////////////
+// ///////////////////////////////////////////////////////////////
 // ///////////////////////////////////////////// class Row
 // ///////////////////////////////////////////////////////////////
 
@@ -188,11 +187,10 @@
         LOG.error("end:     " + end);
         LOG.error("columns: " + columns);
         LOG.error("Actual cells:");
-        for (Iterator i = cells.iterator(); i.hasNext();) {
-          Object component = i.next();
+        for (Object component : cells) {
           if (component instanceof UIComponent) {
-            LOG.error("Cell-ID: " + ((UIComponent)component).getId()
-                + " " + ((UIComponent)component).getRendererType());
+            LOG.error("Cell-ID: " + ((UIComponent) component).getId()
+                + " " + ((UIComponent) component).getRendererType());
           } else {
             LOG.error("Cell:    " + component); // e.g. marker
           }
@@ -208,7 +206,9 @@
 
     private int nextFreeColumn() {
       for (int i = 0; i < columns; i++) {
-        if (FREE.equals(cells.get(i))) return i;
+        if (FREE.equals(cells.get(i))) {
+          return i;
+        }
       }
       return -1;
     }
@@ -253,6 +253,7 @@
       this.rendered = rendered;
     }
 
+    @Override
     public String toString() {
       return name;
     }

Modified: incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/util/LayoutUtil.java
URL: http://svn.apache.org/viewcvs/incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/util/LayoutUtil.java?rev=369754&r1=369753&r2=369754&view=diff
==============================================================================
--- incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/util/LayoutUtil.java (original)
+++ incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/util/LayoutUtil.java Tue Jan 17 03:11:58 2006
@@ -21,7 +21,17 @@
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-import static org.apache.myfaces.tobago.TobagoConstants.*;
+import static org.apache.myfaces.tobago.TobagoConstants.ATTR_HEIGHT;
+import static org.apache.myfaces.tobago.TobagoConstants.ATTR_INLINE;
+import static org.apache.myfaces.tobago.TobagoConstants.ATTR_INNER_HEIGHT;
+import static org.apache.myfaces.tobago.TobagoConstants.ATTR_INNER_WIDTH;
+import static org.apache.myfaces.tobago.TobagoConstants.ATTR_LAYOUT_DIRECTIVE;
+import static org.apache.myfaces.tobago.TobagoConstants.ATTR_LAYOUT_HEIGHT;
+import static org.apache.myfaces.tobago.TobagoConstants.ATTR_LAYOUT_WIDTH;
+import static org.apache.myfaces.tobago.TobagoConstants.ATTR_MINIMUM_SIZE;
+import static org.apache.myfaces.tobago.TobagoConstants.ATTR_WIDTH;
+import static org.apache.myfaces.tobago.TobagoConstants.RENDERER_TYPE_IN;
+import static org.apache.myfaces.tobago.TobagoConstants.RENDERER_TYPE_OUT;
 import org.apache.myfaces.tobago.component.ComponentUtil;
 import org.apache.myfaces.tobago.component.UIForm;
 import org.apache.myfaces.tobago.component.UIPanel;
@@ -32,9 +42,8 @@
 import javax.faces.component.UIInput;
 import javax.faces.component.UINamingContainer;
 import javax.faces.context.FacesContext;
-import java.awt.*;
+import java.awt.Dimension;
 import java.util.ArrayList;
-import java.util.Iterator;
 import java.util.List;
 
 public final class LayoutUtil {
@@ -65,7 +74,7 @@
         spaceInteger = getLayoutHeight(component);
       }
       if (spaceInteger != null) {
-        space = spaceInteger.intValue();
+        space = spaceInteger;
       }
 
 //      if (space < 0 && component.getParent() instanceof UIComponentBase) {
@@ -74,16 +83,15 @@
       }
 
       if (space != -1) {
-        innerSpace =
-            new Integer(getInnerSpace(facesContext, component, space, width));
+        innerSpace = getInnerSpace(facesContext, component, space, width);
       } else {
-        innerSpace = new Integer(-1);
+        innerSpace = -1;
       }
 
       component.getAttributes().put(attribute, innerSpace);
     }
 
-    return innerSpace.intValue();
+    return innerSpace;
   }
 
   public static int getInnerSpace(FacesContext facesContext, UIComponent component,
@@ -195,9 +203,9 @@
     return null;
   }
 
-  public static List addChildren(List children, UIComponent panel) {
-    for (Iterator iter = panel.getChildren().iterator(); iter.hasNext();) {
-      UIComponent child = (UIComponent) iter.next();
+  public static List<UIComponent> addChildren(List<UIComponent> children, UIComponent panel) {
+    for (Object o : panel.getChildren()) {
+      UIComponent child = (UIComponent) o;
       if (isTransparentForLayout(child)) {
         addChildren(children, child);
       } else {
@@ -251,19 +259,17 @@
     if (cell instanceof UIPanel
         && ComponentUtil.getBooleanAttribute(cell,
             ATTR_LAYOUT_DIRECTIVE)) {
-      List children = LayoutUtil.addChildren(new ArrayList(), cell);
-      for (Iterator childs = children.iterator(); childs.hasNext();) {
-        UIComponent component = (UIComponent) childs.next();
+      List<UIComponent> children = addChildren(new ArrayList<UIComponent>(), cell);
+      for (UIComponent component : children) {
         maybeSetLayoutAttribute(component, attribute, value);
       }
     }
   }
 
-
   public static int calculateFixedHeightForChildren(FacesContext facesContext, UIComponent component) {
     int height = 0;
-    for (Iterator iterator = component.getChildren().iterator(); iterator.hasNext();) {
-      UIComponent child = (UIComponent) iterator.next();
+    for (Object o : component.getChildren()) {
+      UIComponent child = (UIComponent) o;
       RendererBase renderer = ComponentUtil.getRenderer(facesContext, child);
       if (renderer == null
           && child instanceof UINamingContainer
@@ -293,7 +299,7 @@
     }
     if (dimension == null) {
       dimension = new Dimension(-1, -1);
-    }    
+    }
     return dimension;
   }