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/08/26 23:20:10 UTC
svn commit: r569883 - in
/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup:
html/list/ html/navigation/paging/ repeater/
Author: ivaynberg
Date: Sun Aug 26 14:20:09 2007
New Revision: 569883
URL: http://svn.apache.org/viewvc?rev=569883&view=rev
Log:
WICKET-882 refactoed onpopulate for abstract repeaters in order to force super.onbeforerender() to be called last
Modified:
wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/list/ListView.java
wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/list/Loop.java
wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/navigation/paging/PagingNavigation.java
wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/repeater/AbstractRepeater.java
wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/repeater/RefreshingView.java
wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/repeater/RepeatingView.java
Modified: wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/list/ListView.java
URL: http://svn.apache.org/viewvc/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/list/ListView.java?rev=569883&r1=569882&r2=569883&view=diff
==============================================================================
--- wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/list/ListView.java (original)
+++ wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/list/ListView.java Sun Aug 26 14:20:09 2007
@@ -31,21 +31,19 @@
/**
- * A ListView is a repeater that makes it easy to display/work with {@link List}s.
- * However, there are situations where it is necessary to work with other
- * collection types, for repeaters that might work better with non-list or
- * database-driven collections see the org.apache.wicket.markup.repeater
- * package.
- *
- * Also notice that in a list the item's uniqueness/primary key/id is identified
- * as its index in the list. If this is not the case you should either override
- * {@link #getListItemModel(IModel, int)} to return a model that will work with
- * the item's true primary key, or use a different repeater that does not rely
- * on the list index.
+ * A ListView is a repeater that makes it easy to display/work with {@link List}s. However, there
+ * are situations where it is necessary to work with other collection types, for repeaters that
+ * might work better with non-list or database-driven collections see the
+ * org.apache.wicket.markup.repeater package.
+ *
+ * Also notice that in a list the item's uniqueness/primary key/id is identified as its index in the
+ * list. If this is not the case you should either override {@link #getListItemModel(IModel, int)}
+ * to return a model that will work with the item's true primary key, or use a different repeater
+ * that does not rely on the list index.
*
*
- * A ListView holds ListItem children. Items can be re-ordered and deleted,
- * either one at a time or many at a time.
+ * A ListView holds ListItem children. Items can be re-ordered and deleted, either one at a time or
+ * many at a time.
* <p>
* Example:
*
@@ -57,8 +55,8 @@
* </pre>
*
* <p>
- * Though this example is about a HTML table, ListView is not at all limited to
- * HTML tables. Any kind of list can be rendered using ListView.
+ * Though this example is about a HTML table, ListView is not at all limited to HTML tables. Any
+ * kind of list can be rendered using ListView.
* <p>
* The related Java code:
*
@@ -76,29 +74,26 @@
* <p>
* <strong>NOTE:</strong>
*
- * When you want to change the default generated markup it is important to
- * realise that the ListView instance itself does not correspond to any markup,
- * however, the generated ListItems do.<br/>
+ * When you want to change the default generated markup it is important to realise that the ListView
+ * instance itself does not correspond to any markup, however, the generated ListItems do.<br/>
*
* This means that methods like {@link #setRenderBodyOnly(boolean)} and
- * {@link #add(org.apache.wicket.behavior.IBehavior)} should be invoked on the
- * {@link ListItem} that is given in {@link #populateItem(ListItem)} method.
+ * {@link #add(org.apache.wicket.behavior.IBehavior)} should be invoked on the {@link ListItem} that
+ * is given in {@link #populateItem(ListItem)} method.
* </p>
*
* <p>
- * <strong>WARNING:</strong> though you can nest ListViews within Forms, you
- * HAVE to set the setReuseItems property to true in order to have validation
- * work properly. By default, setReuseItems is false, which has the effect that
- * ListView replaces all child components by new instances. The idea behind this
- * is that you always render the fresh data, and as people usually use ListViews
- * for displaying read-only lists (at least, that's what we think), this is good
+ * <strong>WARNING:</strong> though you can nest ListViews within Forms, you HAVE to set the
+ * setReuseItems property to true in order to have validation work properly. By default,
+ * setReuseItems is false, which has the effect that ListView replaces all child components by new
+ * instances. The idea behind this is that you always render the fresh data, and as people usually
+ * use ListViews for displaying read-only lists (at least, that's what we think), this is good
* default behavior. <br />
- * However, as the components are replaced before the rendering starts, the
- * search for specific messages for these components fails as they are replaced
- * with other instances. Another problem is that 'wrong' user input is kept as
- * (temporary) instance data of the components. As these components are replaced
- * by new ones, your user will never see the wrong data when setReuseItems is
- * false.
+ * However, as the components are replaced before the rendering starts, the search for specific
+ * messages for these components fails as they are replaced with other instances. Another problem is
+ * that 'wrong' user input is kept as (temporary) instance data of the components. As these
+ * components are replaced by new ones, your user will never see the wrong data when setReuseItems
+ * is false.
* </p>
*
* @author Jonathan Locke
@@ -112,12 +107,11 @@
private int firstIndex = 0;
/**
- * If true, re-rendering the list view is more efficient if the window
- * doesn't get changed at all or if it gets scrolled (compared to paging).
- * But if you modify the listView model object, than you must manually call
- * listView.removeAll() in order to rebuild the ListItems. If you nest a
- * ListView in a Form, ALWAYS set this property to true, as otherwise
- * validation will not work properly.
+ * If true, re-rendering the list view is more efficient if the window doesn't get changed at
+ * all or if it gets scrolled (compared to paging). But if you modify the listView model object,
+ * than you must manually call listView.removeAll() in order to rebuild the ListItems. If you
+ * nest a ListView in a Form, ALWAYS set this property to true, as otherwise validation will not
+ * work properly.
*/
private boolean reuseItems = false;
@@ -163,9 +157,9 @@
}
/**
- * Gets the list of items in the listView. This method is final because it
- * is not designed to be overridden. If it were allowed to be overridden,
- * the values returned by getModelObject() and getList() might not coincide.
+ * Gets the list of items in the listView. This method is final because it is not designed to be
+ * overridden. If it were allowed to be overridden, the values returned by getModelObject() and
+ * getList() might not coincide.
*
* @return The list of items in this list view.
*/
@@ -180,12 +174,11 @@
}
/**
- * If true re-rendering the list view is more efficient if the windows
- * doesn't get changed at all or if it gets scrolled (compared to paging).
- * But if you modify the listView model object, than you must manually call
- * listView.removeAll() in order to rebuild the ListItems. If you nest a
- * ListView in a Form, ALLWAYS set this property to true, as otherwise
- * validation will not work properly.
+ * If true re-rendering the list view is more efficient if the windows doesn't get changed at
+ * all or if it gets scrolled (compared to paging). But if you modify the listView model object,
+ * than you must manually call listView.removeAll() in order to rebuild the ListItems. If you
+ * nest a ListView in a Form, ALLWAYS set this property to true, as otherwise validation will
+ * not work properly.
*
* @return Whether to reuse items
*/
@@ -205,10 +198,9 @@
}
/**
- * Based on the model object's list size, firstIndex and view size,
- * determine what the view size really will be. E.g. default for viewSize is
- * Integer.MAX_VALUE, if not set via setViewSize(). If the underlying list
- * has 10 elements, the value returned by getViewSize() will be 10 if
+ * Based on the model object's list size, firstIndex and view size, determine what the view size
+ * really will be. E.g. default for viewSize is Integer.MAX_VALUE, if not set via setViewSize().
+ * If the underlying list has 10 elements, the value returned by getViewSize() will be 10 if
* startIndex = 0.
*
* @return The number of items to be populated and rendered.
@@ -246,8 +238,7 @@
}
/**
- * Returns a link that will move the given item "down" (towards the end) in
- * the listView.
+ * Returns a link that will move the given item "down" (towards the end) in the listView.
*
* @param id
* Name of move-down link component to create
@@ -303,8 +294,7 @@
}
/**
- * Returns a link that will move the given item "up" (towards the beginning)
- * in the listView.
+ * Returns a link that will move the given item "up" (towards the beginning) in the listView.
*
* @param id
* Name of move-up link component to create
@@ -361,8 +351,7 @@
}
/**
- * Returns a link that will remove this ListItem from the ListView that
- * holds it.
+ * Returns a link that will remove this ListItem from the ListView that holds it.
*
* @param id
* Name of remove link component to create
@@ -406,12 +395,11 @@
}
/**
- * Sets the model as the provided list and removes all children, so that the
- * next render will be using the contents of the model.
+ * Sets the model as the provided list and removes all children, so that the next render will be
+ * using the contents of the model.
*
* @param list
- * The list for the new model. The list must implement
- * {@link Serializable}.
+ * The list for the new model. The list must implement {@link Serializable}.
* @return This for chaining
*/
public Component setList(List list)
@@ -420,8 +408,8 @@
}
/**
- * Sets the model and removes all current children, so that the next render
- * will be using the contents of the model.
+ * Sets the model and removes all current children, so that the next render will be using the
+ * contents of the model.
*
* @param model
* The new model
@@ -435,12 +423,11 @@
}
/**
- * If true re-rendering the list view is more efficient if the windows
- * doesn't get changed at all or if it gets scrolled (compared to paging).
- * But if you modify the listView model object, than you must manually call
- * listView.removeAll() in order to rebuild the ListItems. If you nest a
- * ListView in a Form, ALLWAYS set this property to true, as otherwise
- * validation will not work properly.
+ * If true re-rendering the list view is more efficient if the windows doesn't get changed at
+ * all or if it gets scrolled (compared to paging). But if you modify the listView model object,
+ * than you must manually call listView.removeAll() in order to rebuild the ListItems. If you
+ * nest a ListView in a Form, ALLWAYS set this property to true, as otherwise validation will
+ * not work properly.
*
* @param reuseItems
* Whether to reuse the child items.
@@ -495,13 +482,11 @@
}
/**
- * Subclasses may provide their own ListItemModel with extended
- * functionality. The default ListItemModel works fine with mostly static
- * lists where index remains valid. In cases where the underlying list
- * changes a lot (many users using the application), it may not longer be
- * appropriate. In that case your own ListItemModel implementation should
- * use an id (e.g. the database' record id) to identify and load the list
- * item model object.
+ * Subclasses may provide their own ListItemModel with extended functionality. The default
+ * ListItemModel works fine with mostly static lists where index remains valid. In cases where
+ * the underlying list changes a lot (many users using the application), it may not longer be
+ * appropriate. In that case your own ListItemModel implementation should use an id (e.g. the
+ * database' record id) to identify and load the list item model object.
*
* @param listViewModel
* The ListView's model
@@ -526,76 +511,72 @@
}
/**
- * @see org.apache.wicket.MarkupContainer#onBeforeRender()
+ * @see org.apache.wicket.markup.repeater.AbstractRepeater#onPopulate()
*/
- protected void onBeforeRender()
+ protected void onPopulate()
{
- if (isVisibleInHierarchy())
+ // Get number of items to be displayed
+ final int size = getViewSize();
+ if (size > 0)
{
- // Get number of items to be displayed
- final int size = getViewSize();
- if (size > 0)
+ if (getReuseItems())
{
- if (getReuseItems())
+ // Remove all ListItems no longer required
+ final int maxIndex = firstIndex + size;
+ for (final Iterator iterator = iterator(); iterator.hasNext();)
{
- // 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 next child component
- final ListItem child = (ListItem)iterator.next();
- if (child != null)
+ final int index = child.getIndex();
+ if (index < firstIndex || index >= maxIndex)
{
- final int index = child.getIndex();
- if (index < firstIndex || index >= maxIndex)
- {
- iterator.remove();
- }
+ iterator.remove();
}
}
}
- 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 item = (ListItem)get(Integer.toString(index));
- if (item == null)
- {
- // Create item for index
- item = newItem(index);
-
- // Add list item
- add(item);
-
- // Populate the list item
- onBeginPopulateItem(item);
- populateItem(item);
- }
- }
}
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 item = (ListItem)get(Integer.toString(index));
+ if (item == null)
+ {
+ // Create item for index
+ item = newItem(index);
+
+ // Add list item
+ add(item);
+
+ // Populate the list item
+ onBeginPopulateItem(item);
+ populateItem(item);
+ }
+ }
}
- super.onBeforeRender();
+ else
+ {
+ removeAll();
+ }
+
}
/**
- * Comes handy for ready made ListView based components which must implement
- * populateItem() but you don't want to lose compile time error checking
- * reminding the user to implement abstract populateItem().
+ * Comes handy for ready made ListView based components which must implement populateItem() but
+ * you don't want to lose compile time error checking reminding the user to implement abstract
+ * populateItem().
*
* @param item
*/
Modified: wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/list/Loop.java
URL: http://svn.apache.org/viewvc/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/list/Loop.java?rev=569883&r1=569882&r2=569883&view=diff
==============================================================================
--- wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/list/Loop.java (original)
+++ wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/list/Loop.java Sun Aug 26 14:20:09 2007
@@ -26,12 +26,11 @@
import org.apache.wicket.util.collections.ReadOnlyIterator;
/**
- * A very simple loop component whose model is an Integer defining the number of
- * iterations the loop should render. During rendering, Loop iterates from 0 to
- * getIterations() - 1, creating a new MarkupContainer for each iteration. The
- * MarkupContainer is populated by the Loop subclass by implementing the
- * abstract method populate(LoopItem). The populate() method is called just
- * before the LoopItem container is rendered.
+ * A very simple loop component whose model is an Integer defining the number of iterations the loop
+ * should render. During rendering, Loop iterates from 0 to getIterations() - 1, creating a new
+ * MarkupContainer for each iteration. The MarkupContainer is populated by the Loop subclass by
+ * implementing the abstract method populate(LoopItem). The populate() method is called just before
+ * the LoopItem container is rendered.
*
* @author Juergen Donnerstag
* @author Eelco Hillenius
@@ -111,31 +110,26 @@
/**
* @see org.apache.wicket.Component#onBeforeRender()
*/
- protected void onBeforeRender()
+ protected void onPopulate()
{
- if (isVisibleInHierarchy())
- {
- // Remove any previous loop contents
- removeAll();
+ // Remove any previous loop contents
+ removeAll();
- // Get number of iterations
- final int iterations = getIterations();
- if (iterations > 0)
+ // Get number of iterations
+ final int iterations = getIterations();
+ if (iterations > 0)
+ {
+ // Create LoopItems for each iteration
+ for (int iteration = 0; iteration < iterations; iteration++)
{
- // Create LoopItems for each iteration
- for (int iteration = 0; iteration < iterations; iteration++)
- {
- // Create item for loop iteration
- LoopItem item = newItem(iteration);
-
- // Add and populate item
- add(item);
- populateItem(item);
- }
+ // Create item for loop iteration
+ LoopItem item = newItem(iteration);
+
+ // Add and populate item
+ add(item);
+ populateItem(item);
}
}
-
- super.onBeforeRender();
}
Modified: wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/navigation/paging/PagingNavigation.java
URL: http://svn.apache.org/viewvc/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/navigation/paging/PagingNavigation.java?rev=569883&r1=569882&r2=569883&view=diff
==============================================================================
--- wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/navigation/paging/PagingNavigation.java (original)
+++ wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/navigation/paging/PagingNavigation.java Sun Aug 26 14:20:09 2007
@@ -21,12 +21,10 @@
import org.apache.wicket.version.undo.Change;
/**
- * A navigation for a PageableListView that holds links to other pages of the
- * PageableListView.
+ * A navigation for a PageableListView that holds links to other pages of the PageableListView.
* <p>
- * For each row (one page of the list of pages) a {@link PagingNavigationLink}will
- * be added that contains a {@link Label} with the page number of that link
- * (1..n).
+ * For each row (one page of the list of pages) a {@link PagingNavigationLink}will be added that
+ * contains a {@link Label} with the page number of that link (1..n).
*
* <pre>
*
@@ -46,58 +44,60 @@
*
* </p>
* <p>
- * Override method populateItem to customize the rendering of the navigation.
- * For instance:
+ * Override method populateItem to customize the rendering of the navigation. For instance:
*
* <pre>
- * protected void populateItem(LoopItem loopItem) {
- * final int page = loopItem.getIteration();
- * final PagingNavigationLink link = new PagingNavigationLink("pageLink", pageableListView, page);
- * if (page > 0) {
- * loopItem.add(new Label("separator", "|"));
- * } else {
- * loopItem.add(new Label("separator", ""));
- * }
- * link.add(new Label("pageNumber", String.valueOf(page + 1)));
- * link.add(new Label("pageLabel", "page"));
- * loopItem.add(link);
- * }
+ * protected void populateItem(LoopItem loopItem)
+ * {
+ * final int page = loopItem.getIteration();
+ * final PagingNavigationLink link = new PagingNavigationLink("pageLink", pageableListView, page);
+ * if (page > 0)
+ * {
+ * loopItem.add(new Label("separator", "|"));
+ * }
+ * else
+ * {
+ * loopItem.add(new Label("separator", ""));
+ * }
+ * link.add(new Label("pageNumber", String.valueOf(page + 1)));
+ * link.add(new Label("pageLabel", "page"));
+ * loopItem.add(link);
+ * }
* </pre>
*
* With:
*
* <pre>
- * <span wicket:id="navigation">
- * <span wicket:id="separator"></span>
- * <a wicket:id="pageLink" href="#">
- * <span wicket:id="pageLabel"></span><span wicket:id="pageNumber"></span>
- * </a>
- * </span>
+ * <span wicket:id="navigation">
+ * <span wicket:id="separator"></span>
+ * <a wicket:id="pageLink" href="#">
+ * <span wicket:id="pageLabel"></span><span wicket:id="pageNumber"></span>
+ * </a>
+ * </span>
* </pre>
*
* renders like:
*
* <pre>
- * page1 | page2 | page3 | page4 | page5 | page6 | page7 | page8 | page9
+ * page1 | page2 | page3 | page4 | page5 | page6 | page7 | page8 | page9
* </pre>
*
* </p>
- * Assuming a PageableListView with 1000 entries and not more than 10 lines
- * shall be printed per page, the navigation bar would have 100 entries. Because
- * this is not feasible PagingNavigation's navigation bar is pageable as well.
+ * Assuming a PageableListView with 1000 entries and not more than 10 lines shall be printed per
+ * page, the navigation bar would have 100 entries. Because this is not feasible PagingNavigation's
+ * navigation bar is pageable as well.
* <p>
- * The page links displayed are automatically adjusted based on the number of
- * page links to be displayed and a margin. The margin makes sure that the page
- * link pointing to the current page is not at the left or right end of the page
- * links currently printed and thus providing a better user experience.
+ * The page links displayed are automatically adjusted based on the number of page links to be
+ * displayed and a margin. The margin makes sure that the page link pointing to the current page is
+ * not at the left or right end of the page links currently printed and thus providing a better user
+ * experience.
* <p>
- * Use setMargin() and setViewSize() to adjust the navigation's bar view size
- * and margin.
+ * Use setMargin() and setViewSize() to adjust the navigation's bar view size and margin.
* <p>
* Please
*
- * @see PagingNavigator for a ready made component which already includes links
- * to the first, previous, next and last page.
+ * @see PagingNavigator for a ready made component which already includes links to the first,
+ * previous, next and last page.
*
* @author Jonathan Locke
* @author Eelco Hillenius
@@ -108,8 +108,8 @@
private static final long serialVersionUID = 1L;
/**
- * Undo change for navigation start index. Makes certain that back button
- * works with paging in the navigator.
+ * Undo change for navigation start index. Makes certain that back button works with paging in
+ * the navigator.
*/
private final class StartIndexChange extends Change
{
@@ -155,8 +155,8 @@
private int startIndex;
/**
- * Number of links on the left and/or right to keep the current page link
- * somewhere near the middle.
+ * Number of links on the left and/or right to keep the current page link somewhere near the
+ * middle.
*/
private int margin = -1;
@@ -190,8 +190,7 @@
* @param pageable
* The underlying pageable component to navigate
* @param labelProvider
- * The label provider for the text that the links should be
- * displaying.
+ * The label provider for the text that the links should be displaying.
*/
public PagingNavigation(final String id, final IPageable pageable,
final IPagingLabelProvider labelProvider)
@@ -203,8 +202,7 @@
}
/**
- * Gets the margin, default value is half the view size, unless explicitly
- * set.
+ * Gets the margin, default value is half the view size, unless explicitly set.
*
* @return the margin
*/
@@ -244,7 +242,7 @@
*/
public void setViewSize(final int size)
{
- this.viewSize = size;
+ viewSize = size;
}
/**
@@ -270,35 +268,34 @@
}
/**
- * @see org.apache.wicket.Component#onBeforeRender()
+ * @see org.apache.wicket.markup.html.list.Loop#onPopulate()
*/
- protected void onBeforeRender()
+ protected void onPopulate()
{
-
+
// PagingNavigation itself (as well as the PageableListView)
// may have pages.
// The index of the first page link depends on the PageableListView's
// page currently printed.
- this.setStartIndex();
- super.onBeforeRender();
+ setStartIndex();
+ super.onPopulate();
}
/**
- * Allow subclasses replacing populateItem to calculate the current page
- * number
+ * Allow subclasses replacing populateItem to calculate the current page number
*
* @return start index
*/
protected final int getStartIndex()
{
- return this.startIndex;
+ return startIndex;
}
/**
- * Populate the current cell with a page link (PagingNavigationLink)
- * enclosing the page number the link is pointing to. Subclasses may provide
- * there own implementation adding more sophisticated page links.
+ * Populate the current cell with a page link (PagingNavigationLink) enclosing the page number
+ * the link is pointing to. Subclasses may provide there own implementation adding more
+ * sophisticated page links.
*
* @see org.apache.wicket.markup.html.list.Loop#populateItem(Loop.LoopItem)
*/
@@ -359,13 +356,13 @@
}
/**
- * Get the first page link to render. Adjust the first page link based on
- * the current PageableListView page displayed.
+ * Get the first page link to render. Adjust the first page link based on the current
+ * PageableListView page displayed.
*/
private void setStartIndex()
{
// Which startIndex are we currently using
- int firstListItem = this.startIndex;
+ int firstListItem = startIndex;
// How many page links shall be displayed
int viewSize = Math.min(getViewSize(), pageable.getPageCount());
@@ -398,17 +395,17 @@
firstListItem = 0;
}
- if ((viewSize != getIterations()) || (this.startIndex != firstListItem))
+ if ((viewSize != getIterations()) || (startIndex != firstListItem))
{
- this.modelChanging();
+ modelChanging();
// Tell the ListView what the new start index shall be
- addStateChange(new StartIndexChange(this.startIndex));
- this.startIndex = firstListItem;
+ addStateChange(new StartIndexChange(startIndex));
+ startIndex = firstListItem;
- this.setIterations(Math.min(viewSize, pageable.getPageCount()));
+ setIterations(Math.min(viewSize, pageable.getPageCount()));
- this.modelChanged();
+ modelChanged();
// force all children to be re-rendered
removeAll();
Modified: wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/repeater/AbstractRepeater.java
URL: http://svn.apache.org/viewvc/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/repeater/AbstractRepeater.java?rev=569883&r1=569882&r2=569883&view=diff
==============================================================================
--- wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/repeater/AbstractRepeater.java (original)
+++ wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/repeater/AbstractRepeater.java Sun Aug 26 14:20:09 2007
@@ -26,14 +26,13 @@
import org.slf4j.LoggerFactory;
/**
- * Base class for repeaters. This container renders each of its children using
- * its own markup.
+ * Base class for repeaters. This container renders each of its children using its own markup.
*
- * The children are collected using {@link #renderIterator()} method. This class
- * will take care of properly positioning and rewinding its markup stream so
- * before each child renders it points to the beginning of this component. Each
- * child is rendered by a call to {@link #renderChild(Component)}. A typical
- * implementation simply does <code>child.render(getMarkupStream());</code>.
+ * The children are collected using {@link #renderIterator()} method. This class will take care of
+ * properly positioning and rewinding its markup stream so before each child renders it points to
+ * the beginning of this component. Each child is rendered by a call to
+ * {@link #renderChild(Component)}. A typical implementation simply does
+ * <code>child.render(getMarkupStream());</code>.
*
* @author Igor Vaynberg (ivaynberg)
*/
@@ -65,8 +64,8 @@
}
/**
- * Returns an iterator for the collection of child components to be
- * rendered. Users can override this to change order of rendered children.
+ * Returns an iterator for the collection of child components to be rendered. Users can override
+ * this to change order of rendered children.
*
* @return iterator over child components to be rendered
*/
@@ -104,8 +103,8 @@
}
/**
- * Render a single child. This method can be overridden to modify how a
- * single child component is rendered.
+ * Render a single child. This method can be overridden to modify how a single child component
+ * is rendered.
*
* @param child
* Child component to be rendered
@@ -114,5 +113,22 @@
{
child.render(getMarkupStream());
}
+
+ /**
+ * @see org.apache.wicket.Component#onBeforeRender()
+ */
+ protected final void onBeforeRender()
+ {
+ if (isVisibleInHierarchy())
+ {
+ onPopulate();
+ }
+ super.onBeforeRender();
+ }
+
+ /**
+ * Callback to let the repeater know it should populate itself with its items.
+ */
+ protected abstract void onPopulate();
}
Modified: wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/repeater/RefreshingView.java
URL: http://svn.apache.org/viewvc/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/repeater/RefreshingView.java?rev=569883&r1=569882&r2=569883&view=diff
==============================================================================
--- wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/repeater/RefreshingView.java (original)
+++ wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/repeater/RefreshingView.java Sun Aug 26 14:20:09 2007
@@ -24,23 +24,19 @@
/**
- * An abstract repeater view that provides refreshing functionality to its
- * subclasses. The view is refreshed every request, making it well suited for
- * displaying dynamic data.
+ * An abstract repeater view that provides refreshing functionality to its subclasses. The view is
+ * refreshed every request, making it well suited for displaying dynamic data.
* <p>
- * The view is populated by implementing {@link RefreshingView#getItemModels() }
- * and {@link RefreshingView#populateItem(Item) } methods. RefreshingView builds
- * the items that will be rendered by looping over the models retrieved from
- * {@link RefreshingView#getItemModels() } and calling the
- * {@link RefreshingView#newItem(String, int, IModel) } to generate the child
- * item container followed by a call to
- * {@link RefreshingView#populateItem(Item) } to let the user populate the newly
- * created item container with custom components.
+ * The view is populated by implementing {@link RefreshingView#getItemModels() } and
+ * {@link RefreshingView#populateItem(Item) } methods. RefreshingView builds the items that will be
+ * rendered by looping over the models retrieved from {@link RefreshingView#getItemModels() } and
+ * calling the {@link RefreshingView#newItem(String, int, IModel) } to generate the child item
+ * container followed by a call to {@link RefreshingView#populateItem(Item) } to let the user
+ * populate the newly created item container with custom components.
* </p>
* <p>
* The provided {@link ModelIteratorAdapter} can make implementing
- * {@link RefreshingView#getItemModels() } easier if you have an iterator over
- * item objects.
+ * {@link RefreshingView#getItemModels() } easier if you have an iterator over item objects.
* </p>
*
* @see RepeatingView
@@ -54,8 +50,8 @@
private static final long serialVersionUID = 1L;
/**
- * The item reuse strategy that will be used to recycle items when the page
- * is changed or the view is redrawn.
+ * The item reuse strategy that will be used to recycle items when the page is changed or the
+ * view is redrawn.
*
* @see IItemReuseStrategy
*/
@@ -86,33 +82,29 @@
}
/**
- * Refresh the items in the view. Delegates the creation of items to the
- * selected item reuse strategy
+ * Refresh the items in the view. Delegates the creation of items to the selected item reuse
+ * strategy
*/
- protected void onBeforeRender()
+ protected void onPopulate()
{
- if (isVisibleInHierarchy())
+
+ IItemFactory itemFactory = new IItemFactory()
{
- IItemFactory itemFactory = new IItemFactory()
+ public Item newItem(int index, IModel model)
{
-
- public Item newItem(int index, IModel model)
- {
- String id = RefreshingView.this.newChildId();
- Item item = RefreshingView.this.newItem(id, index, model);
- RefreshingView.this.populateItem(item);
- return item;
- }
-
- };
-
- Iterator models = getItemModels();
- Iterator items = getItemReuseStrategy().getItems(itemFactory, models, getItems());
- removeAll();
- addItems(items);
- }
- super.onBeforeRender();
+ String id = RefreshingView.this.newChildId();
+ Item item = RefreshingView.this.newItem(id, index, model);
+ RefreshingView.this.populateItem(item);
+ return item;
+ }
+
+ };
+
+ Iterator models = getItemModels();
+ Iterator items = getItemReuseStrategy().getItems(itemFactory, models, getItems());
+ removeAll();
+ addItems(items);
}
/**
@@ -125,8 +117,7 @@
/**
* Populate the given Item container.
* <p>
- * <b>be carefull</b> to add any components to the item and not the view
- * itself. So, don't do:
+ * <b>be carefull</b> to add any components to the item and not the view itself. So, don't do:
*
* <pre>
* add(new Label("foo", "bar"));
@@ -146,9 +137,8 @@
protected abstract void populateItem(final Item item);
/**
- * Factory method for Item container. Item containers are simple
- * MarkupContainer used to aggregate the user added components for a row
- * inside the view.
+ * Factory method for Item container. Item containers are simple MarkupContainer used to
+ * aggregate the user added components for a row inside the view.
*
* @see Item
* @param id
@@ -174,8 +164,8 @@
}
/**
- * Add items to the view. Prior to this all items were removed so every
- * request this function starts from a clean slate.
+ * Add items to the view. Prior to this all items were removed so every request this function
+ * starts from a clean slate.
*
* @param items
* item instances to be added to this view
@@ -193,8 +183,8 @@
// /////////////////////////////////////////////////////////////////////////
/**
- * @return currently set item reuse strategy. Defaults to
- * <code>DefaultItemReuseStrategy</code> if none was set.
+ * @return currently set item reuse strategy. Defaults to <code>DefaultItemReuseStrategy</code>
+ * if none was set.
*
* @see DefaultItemReuseStrategy
*/
@@ -208,8 +198,7 @@
}
/**
- * Sets the item reuse strategy. This strategy controls the creation of
- * {@link Item}s.
+ * Sets the item reuse strategy. This strategy controls the creation of {@link Item}s.
*
* @see IItemReuseStrategy
*
Modified: wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/repeater/RepeatingView.java
URL: http://svn.apache.org/viewvc/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/repeater/RepeatingView.java?rev=569883&r1=569882&r2=569883&view=diff
==============================================================================
--- wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/repeater/RepeatingView.java (original)
+++ wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/repeater/RepeatingView.java Sun Aug 26 14:20:09 2007
@@ -24,8 +24,8 @@
/**
* <p>
- * A repeater view that renders all of its children, using its body markup, in
- * the order they were added.
+ * A repeater view that renders all of its children, using its body markup, in the order they were
+ * added.
*
* </p>
* Example:
@@ -55,17 +55,15 @@
* <ul><li>hello</li><li>goodbye</li><li>good morning</li></ul>
* </pre>
*
- * To expand a bit: the repeater itself produces no markup, instead every direct
- * child inherits the entire markup of the repeater. In the example above
- * reeaters's markup is:
+ * To expand a bit: the repeater itself produces no markup, instead every direct child inherits the
+ * entire markup of the repeater. In the example above reeaters's markup is:
*
* <pre>
* <li wicket:id="repeater"></li>
* </pre>
*
- * and so this is the markup that is available to the direct children - the
- * Label components. So as each label renders it produces a line of the output
- * that has the <code>li</code>tag.
+ * and so this is the markup that is available to the direct children - the Label components. So as
+ * each label renders it produces a line of the output that has the <code>li</code>tag.
*
*
* @author Igor Vaynberg ( ivaynberg )
@@ -94,9 +92,8 @@
}
/**
- * Generates a unique id string. This makes it easy to add items to be
- * rendered w/out having to worry about generating unique id strings in your
- * code.
+ * Generates a unique id string. This makes it easy to add items to be rendered w/out having to
+ * worry about generating unique id strings in your code.
*
* @return unique child id
*/
@@ -121,6 +118,14 @@
protected Iterator renderIterator()
{
return iterator();
+ }
+
+ /**
+ * @see org.apache.wicket.markup.repeater.AbstractRepeater#onPopulate()
+ */
+ protected void onPopulate()
+ {
+ // noop - population of this repeater is manual
}
}