wicket.markup.html.navigation.paging
Class PagingNavigation

java.lang.Object
  extended by wicket.Component
      extended by wicket.MarkupContainer
          extended by wicket.markup.html.WebMarkupContainer
              extended by wicket.markup.html.list.Loop
                  extended by wicket.markup.html.navigation.paging.PagingNavigation
All Implemented Interfaces:
java.io.Serializable
Direct Known Subclasses:
AjaxPagingNavigation

public class PagingNavigation
extends Loop

A navigation for a PageableListView that holds links to other pages of the PageableListView.

For each row (one page of the list of pages) a PagingNavigationLinkwill be added that contains a Labelwith the page number of that link (1..n).

  
        <td wicket:id="navigation">
                <a wicket:id="pageLink" href="SearchCDPage.html">
                        <span wicket:id="pageNumber">1</>
                </a>
        </td>
        
 
thus renders like:
  
        1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 |
        
 

Override method populateItem to customize the rendering of the navigation. For instance:

 protected void populateItem(ListItem listItem)
 {
        final int page = ((Integer)listItem.getModelObject()).intValue();
        final PagingNavigationLink link = new PagingNavigationLink("pageLink", pageableListView, page);
        if (page > 0)
        {
                listItem.add(new Label("separator", "|"));
        }
        else
        {
                listItem.add(new Label("separator", ""));
        }
        link.add(new Label("pageNumber", String.valueOf(page + 1)));
        link.add(new Label("pageLabel", "page"));
        listItem.add(link);
 }
 
With:
        <td wicket:id="navigation">
          <span wicket:id="separator"/>
          <a wicket:id="pageLink" href="#">
            <span wicket:id="pageLabel"/><span wicket:id="pageNumber"/>
          </a>
        </td>
 
renders like:
 page1 | page2 | page3 | page4 | page5 | page6 | page7 | page8 | page9
 

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.

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.

Use setMargin() and setViewSize() to adjust the navigation's bar view size and margin.

Please

Author:
Jonathan Locke, Eelco Hillenius, Juergen Donnerstag
See Also:
for a ready made component which already includes links to the first, previous, next and last page., Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class wicket.markup.html.list.Loop
Loop.LoopItem
 
Nested classes/interfaces inherited from class wicket.Component
Component.ComponentModelChange, Component.EnabledChange, Component.IVisitor, Component.VisibilityChange
 
Field Summary
protected  IPagingLabelProvider labelProvider
          The label provider for the text that the links should be displaying.
protected  IPageable pageable
          The PageableListView this navigation is navigating.
 
Fields inherited from class wicket.Component
ENABLE, FLAG_RESERVED1, FLAG_RESERVED2, FLAG_RESERVED3, FLAG_RESERVED4, FLAG_RESERVED5, FLAG_RESERVED6, FLAG_RESERVED7, FLAG_RESERVED8, PATH_SEPARATOR, RENDER
 
Constructor Summary
PagingNavigation(java.lang.String id, IPageable pageable)
          Constructor.
PagingNavigation(java.lang.String id, IPageable pageable, IPagingLabelProvider labelProvider)
          Constructor.
 
Method Summary
 int getMargin()
          Gets the margin, default value is half the view size, unless explicitly set.
 java.lang.String getSeparator()
          Gets the seperator.
protected  int getStartIndex()
          Allow subclasses replacing populateItem to calculate the current page number
 int getViewSize()
          Gets the view size (is fixed by user).
protected  void internalOnAttach()
          THIS METHOD IS NOT PART OF THE WICKET PUBLIC API.
protected  PagingNavigationLink newPagingNavigationLink(java.lang.String id, IPageable pageable, int pageIndex)
          Factory method for creating page number links.
protected  void populateItem(Loop.LoopItem loopItem)
          Populate the current cell with a page link (PagingNavigationLink) enclosing the page number the link is pointing to.
protected  void renderItem(Loop.LoopItem loopItem)
          Renders the page link.
 void setMargin(int margin)
          Sets the margin.
 void setSeparator(java.lang.String separator)
          Sets the seperator.
 void setViewSize(int size)
          view size of the navigation bar.
 
Methods inherited from class wicket.markup.html.list.Loop
getIterations, newItem, onRender
 
Methods inherited from class wicket.markup.html.WebMarkupContainer
getMarkupType, getWebPage
 
Methods inherited from class wicket.MarkupContainer
add, autoAdd, contains, findMarkupStream, get, getAssociatedMarkupStream, getMarkupStream, internalAdd, internalAttach, internalDetach, isTransparentResolver, iterator, iterator, newMarkupResourceStream, onComponentTagBody, remove, remove, removeAll, renderAll, renderAssociatedMarkup, renderComponentTagBody, replace, setMarkupStream, setModel, size, toString, toString, visitChildren, visitChildren
 
Methods inherited from class wicket.Component
add, addStateChange, checkComponentTag, checkComponentTagAttribute, continueToOriginalDestination, debug, detachBehaviors, detachModel, detachModels, error, exceptionMessage, fatal, findPage, findParent, findParentWithAssociatedMarkup, getApplication, getApplicationPages, getApplicationSettings, getBehaviors, getBehaviors, getClassRelativePath, getConverter, getEscapeModelStrings, getFeedbackMessage, getFlag, getFlag, getId, getLocale, getLocalizer, getMarkupAttributes, getMarkupId, getMetaData, getModel, getModelComparator, getModelObject, getModelObjectAsString, getOutputMarkupId, getPage, getPageFactory, getPageRelativePath, getParent, getPath, getRenderBodyOnly, getRequest, getRequestCycle, getResponse, getSession, getSizeInBytes, getString, getString, getString, getStyle, getVariation, hasErrorMessage, hasFeedbackMessage, info, initModel, internalOnDetach, internalOnModelChanged, isActionAuthorized, isAncestorOf, isBehaviorAccepted, isEnableAllowed, isEnabled, isHeadRendered, isIgnoreAttributeModifier, isRenderAllowed, isVersioned, isVisible, isVisibleInHierarchy, modelChanged, modelChanging, newPage, newPage, onAfterRender, onAttach, onBeforeRender, onBeginRequest, onComponentTag, onDetach, onEndRequest, onModelChanged, onModelChanging, onRender, redirectToInterceptPage, remove, render, render, renderComponent, renderComponent, renderComponentTag, rendered, renderedBehaviors, renderHead, replaceComponentTagBody, replaceWith, resetHeadRendered, sameRootModel, sameRootModel, setAuto, setEnabled, setEscapeModelStrings, setFlag, setFlag, setIgnoreAttributeModifier, setMetaData, setModelObject, setOutputMarkupId, setRedirect, setRenderBodyOnly, setResponsePage, setResponsePage, setResponsePage, setVersioned, setVisible, urlFor, urlFor, urlFor, urlFor, urlFor, visitParents, warn
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

pageable

protected IPageable pageable
The PageableListView this navigation is navigating.


labelProvider

protected IPagingLabelProvider labelProvider
The label provider for the text that the links should be displaying.

Constructor Detail

PagingNavigation

public PagingNavigation(java.lang.String id,
                        IPageable pageable)
Constructor.

Parameters:
id - See Component
pageable - The underlying pageable component to navigate

PagingNavigation

public PagingNavigation(java.lang.String id,
                        IPageable pageable,
                        IPagingLabelProvider labelProvider)
Constructor.

Parameters:
id - See Component
pageable - The underlying pageable component to navigate
labelProvider - The label provider for the text that the links should be displaying.
Method Detail

getMargin

public int getMargin()
Gets the margin, default value is half the view size, unless explicitly set.

Returns:
the margin

getSeparator

public java.lang.String getSeparator()
Gets the seperator.

Returns:
the seperator

getViewSize

public int getViewSize()
Gets the view size (is fixed by user).

Returns:
view size

setViewSize

public void setViewSize(int size)
view size of the navigation bar.

Parameters:
size -

setMargin

public void setMargin(int margin)
Sets the margin.

Parameters:
margin - the margin

setSeparator

public void setSeparator(java.lang.String separator)
Sets the seperator. Null meaning, no separator at all.

Parameters:
separator - the seperator

internalOnAttach

protected void internalOnAttach()
Description copied from class: Component
THIS METHOD IS NOT PART OF THE WICKET PUBLIC API. DO NOT CALL OR OVERRIDE. Called when a request begins.

Overrides:
internalOnAttach in class Loop
See Also:
Component.internalOnAttach()

getStartIndex

protected final int getStartIndex()
Allow subclasses replacing populateItem to calculate the current page number

Returns:
start index

populateItem

protected void populateItem(Loop.LoopItem loopItem)
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.

Specified by:
populateItem in class Loop
Parameters:
loopItem - The iteration of the loop
See Also:
Loop.populateItem(Loop.LoopItem)

newPagingNavigationLink

protected PagingNavigationLink newPagingNavigationLink(java.lang.String id,
                                                       IPageable pageable,
                                                       int pageIndex)
Factory method for creating page number links.

Parameters:
id - the component id.
pageable - the pageable for the link
pageIndex - the page index the link points to
Returns:
the page navigation link.

renderItem

protected void renderItem(Loop.LoopItem loopItem)
Renders the page link. Add the separator if not the last page link

Overrides:
renderItem in class Loop
Parameters:
loopItem - The loop iteration
See Also:
Loop.renderItem(Loop.LoopItem)


Copyright © 2004-2007 Wicket developers. All Rights Reserved.