You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by iv...@apache.org on 2007/01/04 20:05:05 UTC

svn commit: r492685 - /incubator/wicket/trunk/wicket/src/main/java/wicket/markup/html/list/ListView.java

Author: ivaynberg
Date: Thu Jan  4 11:05:04 2007
New Revision: 492685

URL: http://svn.apache.org/viewvc?view=rev&rev=492685
Log:
factor out item generation from onattach

Modified:
    incubator/wicket/trunk/wicket/src/main/java/wicket/markup/html/list/ListView.java

Modified: incubator/wicket/trunk/wicket/src/main/java/wicket/markup/html/list/ListView.java
URL: http://svn.apache.org/viewvc/incubator/wicket/trunk/wicket/src/main/java/wicket/markup/html/list/ListView.java?view=diff&rev=492685&r1=492684&r2=492685
==============================================================================
--- incubator/wicket/trunk/wicket/src/main/java/wicket/markup/html/list/ListView.java (original)
+++ incubator/wicket/trunk/wicket/src/main/java/wicket/markup/html/list/ListView.java Thu Jan  4 11:05:04 2007
@@ -48,10 +48,10 @@
  * Example:
  * 
  * <pre>
- *       &lt;tbody&gt;
- *         &lt;tr wicket:id=&quot;rows&quot; class=&quot;even&quot;&gt;
- *         &lt;td&gt;&lt;span wicket:id=&quot;id&quot;&gt;Test ID&lt;/span&gt;&lt;/td&gt;
- *       ...    
+ *                   &lt;tbody&gt;
+ *                     &lt;tr wicket:id=&quot;rows&quot; class=&quot;even&quot;&gt;
+ *                     &lt;td&gt;&lt;span wicket:id=&quot;id&quot;&gt;Test ID&lt;/span&gt;&lt;/td&gt;
+ *                   ...    
  * </pre>
  * 
  * <p>
@@ -540,58 +540,68 @@
 
 		if (isVisibleInHierarchy())
 		{
-			// Get number of items to be displayed
-			final int size = getViewSize();
-			if (size > 0)
+			if (getViewSize() > 0)
 			{
-				if (getReuseItems())
-				{
-					// Remove all ListItems no longer required
-					final int maxIndex = firstIndex + size;
-					for (final Iterator iterator = iterator(); iterator.hasNext();)
-					{
-						// Get next child component
-						final ListItem child = (ListItem)iterator.next();
-						if (child != null)
-						{
-							final int index = child.getIndex();
-							if (index < firstIndex || index >= maxIndex)
-							{
-								iterator.remove();
-							}
-						}
-					}
-				}
-				else
-				{
-					// Automatically rebuild all ListItems before rendering the
-					// list view
-					removeAll();
-				}
+				onGenerateItems();
+			}
+			else
+			{
+				removeAll();
+			}
+		}
+	}
 
-				// Loop through the markup in this container for each item
-				for (int i = 0; i < size; i++)
+	/**
+	 * Generates items of the listview. Subclasses can override to introduce a
+	 * different way items can be generated. Newly created items should be
+	 * populated by {@link ListView#populateItem(ListItem)} method.
+	 */
+	protected void onGenerateItems()
+	{
+		// Get number of items to be displayed
+		final int size = getViewSize();
+		if (getReuseItems())
+		{
+			// Remove all ListItems no longer required
+			final int maxIndex = firstIndex + size;
+			for (final Iterator iterator = iterator(); iterator.hasNext();)
+			{
+				// Get next child component
+				final ListItem child = (ListItem)iterator.next();
+				if (child != null)
 				{
-					// Get index
-					final int index = firstIndex + i;
-
-					// If this component does not already exist, populate it
-					ListItem<T> item = (ListItem<T>)get(Integer.toString(index));
-					if (item == null)
+					final int index = child.getIndex();
+					if (index < firstIndex || index >= maxIndex)
 					{
-						// Create item for index
-						item = newItem(index);
-
-						// Populate the list item
-						onBeginPopulateItem(item);
-						populateItem(item);
-						item.attach();
+						iterator.remove();
 					}
 				}
 			}
-			else
+		}
+		else
+		{
+			// Automatically rebuild all ListItems before rendering the
+			// list view
+			removeAll();
+		}
+
+		// Loop through the markup in this container for each item
+		for (int i = 0; i < size; i++)
+		{
+			// Get index
+			final int index = firstIndex + i;
+
+			// If this component does not already exist, populate it
+			ListItem<T> item = (ListItem<T>)get(Integer.toString(index));
+			if (item == null)
 			{
-				removeAll();
+				// Create item for index
+				item = newItem(index);
+
+				// Populate the list item
+				onBeginPopulateItem(item);
+				populateItem(item);
+				item.attach();
 			}
 		}
 	}