I wrote a custom PagingNavigation which renders page links in the form:
[1-5...11-15 *16-20* 21-25...196-200]. The page size is adjustable by a
DropDownChoice. 

Everything works fine until i hit the back-button and then click on one of
the links (e.g. 11-15). What happens then is that in class
"RequestListenerInterface" the request doesn't get processed in the invoke
method, which results in an empty DataView (because my custom
PagingNavigation class does not get called):

if (!component.isEnabledInHierarchy() || !component.isVisibleInHierarchy())
                {
                        // just return so that we have a silent fail and just 
re-render the
                        // page
                        log.warn("component not enabled or visible; ignoring 
call. Component: " +
component);
                        return;
                }

I already searched the mailing list and found, that this has been introduced
because of a security problem. On the one hand i removed every code line
which sets components visibility or enablement to false. That didn't solve
the problem. 

On the other hand even if that worked, i'd have no idea how to get around
this problem, as i  have to set the visibility of loopItems (i overwrote
method "populateItem" in class PagingNavigation) because not every page has
a corresponding link and when instead i call "remove()" on the loopItems,
wicket exits with an exception that the component is "null". 

Thanks for any suggestions!!!

Here's the code of my customized PagingNavigation class:

public class CustomPagingNavigation extends PagingNavigation  {

        private static final long serialVersionUID = -3614988044938070942L;

        private BrowsingItems f;

        private PagingNavigationLink<Void> link;
        
        private int currentPage;

        private BrowsingItems.BrowsingItem selectedBi;

        private BrowsingItems.BrowsingItem pageMatchingBi;
        
        private IPageable pageable;
        
        private int offset = 1;
        
        private IASPPagingDimensionsProvider dimensionsProvider;
        
        private BrowsingItems.BrowsingItem nextBrowsingItem = null;

        public CustomPagingNavigation(String id, IPageable pageable,
                        IPagingLabelProvider labelProvider, 
IASPPagingDimensionsProvider
dimensionsProvider) {
                super(id, pageable, labelProvider);
                this.dimensionsProvider = dimensionsProvider;
                this.pageable = pageable;
                
                setViewSize(dimensionsProvider.getRecordCount() /
dimensionsProvider.getItemsPerPage());
                f = newBrowsingItems();
                f.setOffset(1);
        }

        
        @Override
        protected void populateItem(LoopItem loopItem) {
                setViewSize(dimensionsProvider.getRecordCount() /
dimensionsProvider.getItemsPerPage());
                if (f.getCurrentPage() >= f.getPages())
                        f.setOffset(f.getLastPageOffset());
                if (f.getOffset() < 0)
                        f.setOffset(1);
                if (f.getOffset() > f.getRecordCount())
                        f.setOffset(f.getLastPageOffset());
                currentPage = loopItem.getIteration();
                pageMatchingBi = findMatchingPage(f.getBrowsingItems(), 
currentPage);
                if (pageMatchingBi != null) {
                        boolean selected = false;
                        if (selectedBi == null) {
                                selectedBi = f.getBrowsingItems()[0];
                        }
                        if (selectedBi != null && 
selectedBi.equals(pageMatchingBi)) {
                                selected = true;
                        }
                        link = new 
ASPBrowsingItemPageNavigationLink<Void>("pageLink",
                                        pageable, currentPage, pageMatchingBi, 
selected) {
                                private static final long serialVersionUID = 
7412763652723598668L;

                                @Override
                                public void onClick() {
                                        super.onClick();
                                        selectedBi = this.getBrowsingItem();
                                        offset = 
this.getBrowsingItem().getFrom();
                                        newBrowsingItems();
                                        getPage().setRedirect(true);
                                        // Return the current page.
                                        setResponsePage(getPage());
                                }
                        };
                        loopItem.add(link);
                        loopItem.add(new Label("separator", "&nbsp;")
                                .setEscapeModelStrings(false));
                        nextBrowsingItem = 
f.findNextBrowsingItem(pageMatchingBi);
                        if(nextBrowsingItem != null && 
nextBrowsingItem.isDots()){
                                loopItem.add(newDotsLabel());
                        } else {
                                loopItem.add(newBlankLabel());
                        }
                } else {
                        //Even if i don't do this but instead insert the 
components above i get
the same
                        //error message
                        loopItem.setVisibilityAllowed(false);
                }
        }
        
        private Label newBlankLabel() {
                Label lbl = new Label("dots", "");
                return lbl;
        }
        
        private Label newDotsLabel() {
                Label lbl = new Label("dots", "&hellip;");
                lbl.add(new SimpleAttributeModifier("class", "active"));
                lbl.setEscapeModelStrings(false);
                return lbl;
        }

        public void setSelectedBi(BrowsingItems.BrowsingItem browsingItem) {
                this.selectedBi = browsingItem;
        }

        /**
         * new BrowsingItems.
         * 
         * @return
         */
        private BrowsingItems newBrowsingItems() {
                f = new BrowsingItems();
                f.setRecordCount(dimensionsProvider.getRecordCount());
                f.setPageLength(dimensionsProvider.getItemsPerPage());
                f.setOffset(offset);
                return f;
        }

        /**
         * finds the corresponding BrowsingItem for a given page.
         * 
         * @param bi
         * @param page
         * @return
         */
        private BrowsingItems.BrowsingItem findMatchingPage(
                        BrowsingItems.BrowsingItem[] bi, int page) {
                page = page + 1;
                for (int i = 0; i < bi.length; i++) {
                        if (page == 
bi[i].getPage(dimensionsProvider.getItemsPerPage())) {
                                return bi[i];
                        }
                }
                return null;
        }

        /**
         * marks the next browsing item when clicking the next button
         */
        public void markNextLink() {
                if (selectedBi != null) {
                        newBrowsingItems();
                        f.setOffset(offset);
                        int nextOffset = f.getNextOffset();
                        f.setOffset(nextOffset);
                        this.offset = nextOffset;
                        BrowsingItems.BrowsingItem nextItem = f
                                        .findNextBrowsingItem(selectedBi);
                        this.selectedBi = nextItem;
                }
        }

        /**
         *  marks the previous browsing item when clicking the next button
         */
        public void markPreviousLink() {
                if (selectedBi != null) {
                        newBrowsingItems();
                        f.setOffset(offset);
                        int prevOffset = f.getPreviousOffset();
                        f.setOffset(prevOffset);
                        this.offset = prevOffset;
                        BrowsingItems.BrowsingItem prevItem = f
                                        .findPrevBrowsingItem(selectedBi);
                        this.selectedBi = prevItem;
                }
        }
}


--
View this message in context: 
http://apache-wicket.1842946.n4.nabble.com/Custom-PagingNavigation-Back-Button-Problem-tp3666779p3666779.html
Sent from the Users forum mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org

Reply via email to