You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jetspeed-dev@portals.apache.org by ta...@apache.org on 2006/06/28 21:00:15 UTC

svn commit: r417847 - /portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/layout/impl/PortletPlacementContextImpl.java

Author: taylor
Date: Wed Jun 28 12:00:15 2006
New Revision: 417847

URL: http://svn.apache.org/viewvc?rev=417847&view=rev
Log:
Problem
==========
Using the Ajax API, the user can specify the row to add a portlet.  
If that row is greater than the current number of rows, 
then an ArrayOutOfBounds exception will be thrown and the portlet will not be added.  
It seems like better behavior might be to just add the portlet at the end of the column 
even if it doesn't match the request.  
So just to make it clear, if there are 3 portlets on the page and the user requests that 
a new portlet be added at row 6, it should actually be added at row 4 (index 3 since it is zero based)

Solution
===========
The solution is to check the row before attempting to add it to the Vector.  
If the row exceeds the size of the Vector, then just add the portlet to the end 
of the Vector rather than trying to insert it.

The new code is found within PortletPlacementContextImpl.add(…)  and is shown below:

            // Make sure that the column has room to add the row
            if(row < 0 || row > column.size()) {
                // Add to the end
                column.addElement(fragment);
                row = column.size()-1;
            } else {
                column.add(row, fragment);
            }

I've tested it out and it seems to work just fine.  
Note that the row needed to be adjusted so that the xml response to the 
user would indicate where the portlet was actually added.

Contributed by David Gurney

Modified:
    portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/layout/impl/PortletPlacementContextImpl.java

Modified: portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/layout/impl/PortletPlacementContextImpl.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/layout/impl/PortletPlacementContextImpl.java?rev=417847&r1=417846&r2=417847&view=diff
==============================================================================
--- portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/layout/impl/PortletPlacementContextImpl.java (original)
+++ portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/layout/impl/PortletPlacementContextImpl.java Wed Jun 28 12:00:15 2006
@@ -31,6 +31,7 @@
 import org.apache.jetspeed.om.page.Page;
 import org.apache.jetspeed.request.RequestContext;
 
+
 /**
  * Portal Placement Context
  * 
@@ -90,7 +91,7 @@
 	
     protected Page page;
     protected Fragment root;
-    
+        
 	public PortletPlacementContextImpl(RequestContext requestContext) 
     throws PortletPlacementException 
     {
@@ -367,7 +368,14 @@
                 }
                 
             }
-            column.add(row, fragment);
+            // Make sure that the column has room to add the row
+            if(row < 0 || row > column.size()) {
+            	// Add to the end
+            	column.addElement(fragment);
+            	row = column.size()-1;
+            } else {
+            	column.add(row, fragment);
+            }
             Coordinate newCoord = new CoordinateImpl(col, row, col, row);
             this.fragmentCoordinateMap.put(fragment, newCoord);
             return newCoord;



---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-dev-unsubscribe@portals.apache.org
For additional commands, e-mail: jetspeed-dev-help@portals.apache.org