Thanks Paul, I worked it out and added my solution to a SO question about the same issue: http://stackoverflow.com/questions/4996208/how-do-i-modify-the-markup-generated-by-a-wicket-link-in-a-pagingnavigator
It's the newest answer at the bottom. Daniel On Mon, Jun 24, 2013 at 3:26 PM, Paul Bors <[email protected]> wrote: > See PagingNavigationLink, PagingNavigationIncrementLink and their use by > the > NavigationToolbar as well as their counter parts. > You would have to create your own NavigationToolbar, call super() methods > and replace the PagingNavigationLink with your own. > > If you want to replace the headers then take a look at > FallbackHeadersToolbar. > > That's how I customized them both. > > Here's some code for you to get you started :) > > public class MyAjaxPagingNavigationLink extends AjaxPagingNavigationLink { > private static final long serialVersionUID = 1L; > > private boolean isForLastPageLink; > private boolean hideLastPageLink; > > /** > * Constructor. > * > * @param id > * See Component > * @param iPageable > * The pageable component for this page link > * @param pageNumber > * The page number in the PageableListView that this link > links to. Negative > * pageNumbers are relative to the end of the list. > * @see AjaxPagingNavigationLink > */ > public MyAjaxPagingNavigationLink(String id, IPageable iPageable, int > pageNumber) { > this(id, iPageable, pageNumber, false); > } > > /** > * Constructor. > * > * @param id > * See Component > * @param iPageable > * The pageable component for this page link > * @param pageNumber > * The page number in the PageableListView that this link > links to. Negative > * pageNumbers are relative to the end of the list. > * @param hideLastPageLink > * Boolean flag set to true if the last page link is to be > hidden > * @see AjaxPagingNavigationLink > */ > public MyAjaxPagingNavigationLink(String id, IPageable iPageable, int > pageNumber, boolean hideLastPageLink) { > super(id, iPageable, pageNumber); > this.hideLastPageLink = hideLastPageLink; > isForLastPageLink = pageNumber == -1; > } > > @Override > public void onComponentTagBody(MarkupStream stream, ComponentTag > openTag) { > String src; > if (isForLastPageLink && hideLastPageLink) { > src = ""; > } else { > src = getImageSource(isForLastPageLink, pageable); > > } > replaceComponentTagBody(stream, openTag, src); > } > > public static String getImageSource(boolean forLastPageLink, IPageable > iPageable) { > String buttonLabel = new ResourceModel("button.label").getObject(); > String src = null; > if(forLastPageLink) { > if((iPageable.getCurrentPage() == iPageable.getPageCount() - 1) > || (iPageable.getPageCount() == 0)) { > src = > > RequestCycle.get().getUrlRenderer().renderContextRelativeUrl("images/last_di > sabled.gif"); > } else { > src = > RequestCycle.get().getUrlRenderer().renderContextRelativeUrl("images/ > last.gi > f"); > } > } else { > if(iPageable.getCurrentPage() == 0) { > src = > > RequestCycle.get().getUrlRenderer().renderContextRelativeUrl("images/first_d > isabled.gif"); > } else { > src = > > RequestCycle.get().getUrlRenderer().renderContextRelativeUrl("images/first.g > if"); > } > } > return "<img src=\"" + src + "\" border=\"0\" alt=\"" + > buttonLabel > + "\">"; > } > } > > public class MyAjaxNavigationToolbar extends AjaxNavigationToolbar { > private static final long serialVersionUID = 1L; > > protected boolean showNavigationLabel = true; > > public MyAjaxNavigationToolbar(DataTable<?, ?> table) { > this(table, table.getColumns().size()); > } > > public MyAjaxNavigationToolbar(DataTable<?, ?> table, int > customColspan) > { > super(table); > WebMarkupContainer span = (WebMarkupContainer)this.get("span"); > span.add(new AttributeModifier("colspan", new > Model<String>(String.valueOf(customColspan)))); > } > > @Override > protected PagingNavigator newPagingNavigator(String navigatorId, final > DataTable<?, ?> table) { > return new AjaxPagingNavigator(navigatorId, table) { > private static final long serialVersionUID = 1L; > @Override > protected Link<?> newPagingNavigationIncrementLink(String id, > IPageable pageable, int increment) { > return new MyAjaxPagingNavigationIncrementLink(id, > pageable, > increment); > } > > @Override > protected Link<?> newPagingNavigationLink(String id, IPageable > pageable, int pageNumber) { > return new MyAjaxPagingNavigationLink(id, pageable, > pageNumber) { > private static final long serialVersionUID = 1L; > @Override > public boolean isVisible() { > return !isShortenVersion(); > } > }; > } > > @Override > protected PagingNavigation newNavigation(String id, IPageable > pageable, IPagingLabelProvider labelProvider) { > return new AjaxPagingNavigation("navigation", pageable, > labelProvider) { > private static final long serialVersionUID = 1L; > @Override > protected Link<?> newPagingNavigationLink(String id, > IPageable iPageable, long pageIndex) { > return new AjaxPagingNavigationLink(id, iPageable, > pageIndex); > } > @Override > public boolean isVisible() { > return !isShortenVersion(); > } > }; > } > > @Override > protected void onAjaxEvent(AjaxRequestTarget target) { > updateComponents(target); > target.add(table); > if (target.getPage() instanceof ConsolePage) { > > target.add(((ConsolePage)target.getPage()).getFeedbackPanel()); > } > } > > @Override > public boolean isVisible() { > return table.getPageCount() > 1; > } > }; > } > > @Override > protected WebComponent newNavigatorLabel(String navigatorId, final > DataTable<?, ?> table) { > NavigatorLabel nLabel = new NavigatorLabel(navigatorId, table) { > private static final long serialVersionUID = 1L; > @Override > public boolean isVisible() { > return isShowNavigationLabel(); > } > }; > if (isShortenVersion()) { > nLabel.setDefaultModel( > new StringResourceModel("ShortNavigatorLabel", this, > new Model<NavigationToolbarLabelData>(new > NavigationToolbarLabelData(table)), "${from} to ${to} of ${of}") > ); > } > return nLabel; > } > > /** > * Override method in order to subscribe to Ajax pagination update > events. > */ > protected void updateComponents(AjaxRequestTarget target) { } > > /** > * Predicator for the visibility of the {@link NavigatorLabel}. > * > * @return The visibility state of the navigator label. > */ > public boolean isShowNavigationLabel() { > return showNavigationLabel; > } > > /** > * Mutator for the navigation labels. > * > * @param showStrechComponent Boolean flag set to <code>true</code> > if > the > * navigation labels are to be displayed. > * @return A reference back to the same instance of this class object, > * useful to chain calls. > */ > public MyAjaxNavigationToolbar setShowNavigationLabel(boolean > showStrechComponent) { > showNavigationLabel = showStrechComponent; > return this; > } > > /** > * Controls the {@link NavigatorLabel}'s format that provides Showing x > to y of z message given for a DataTable.<br> > * The default of <code>false</code> would use the longer <code>Showing > ${from} to ${to} of ${of}</code> format > * while if overridden to return <code>true</code> then the shorter > <code>${from} to ${to} of ${of}</code> format > * will be used > * > * @return <code>false</code> by default to show the long format. > */ > public boolean isShortenVersion() { > return false; > } > } > > ~ Thank you, > Paul Bors > > -----Original Message----- > From: Daniel Watrous [mailto:[email protected]] > Sent: Monday, June 24, 2013 4:15 PM > To: [email protected] > Subject: Customizing links in Paging > > Hello, > > I'm using the Paging functionality with my DataProvider. I've been trying > to > make a simple change, but it's turned out to be very difficult. > Hopefully you can give a little help. > > I have a class that extends PagingNavigator and provides markup specific to > my theme. When the paging links render, the current page doesn't render > with > an <a> tag around it. It's stripped away. > > I've traced through and found that this is most likely due to AutoEnable > being set to true in the Link that's created. That choice is hard coded in > to the PagingNavigationLink class. > > I'm trying to avoid extending all of the Paging related classes down to the > PagingNavigationLink in order to customize this behavior. Is there some way > to have that active page render inside an <a> tag with no href? > > Thanks, > Daniel > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [email protected] > For additional commands, e-mail: [email protected] > >
