0

Hi everyone I am facing problems with my grid and paging toolbar. On every page I should show 9 items. When I have, for example 15 items, when loader is trying to load second page, first he gives me the second page but right after that he backs me to the first page. If I have 20 or more items, first and second pages are okay, but third is having problems like I wrote in last sentence(backs me to the first page). If I have 4 pages, first 3 are okay, but the last is problem So, every time LAST PAGE is a problem. This is my class with Grid and Paging Toolbar:

public abstract class EntityGrid<M extends GwtEntityModel> extends ContentPanel {

    private static final ConsoleMessages MSGS = GWT.create(ConsoleMessages.class);

    private static final int ENTITY_PAGE_SIZE = 10;

    protected GwtSession currentSession;
    private AbstractEntityView<M> parentEntityView;

    private EntityCRUDToolbar<M> entityCRUDToolbar;
    protected MyGrid<M> entityGrid;
    protected BasePagingLoader<PagingLoadResult<M>> entityLoader;
    protected ListStore<M> entityStore;
    protected PagingToolBar entityPagingToolbar;
    protected EntityFilterPanel<M> filterPanel;

    protected EntityGrid(AbstractEntityView<M> entityView, GwtSession currentSession) {
        super(new FitLayout());
        //
        // Set other properties
        this.parentEntityView = entityView;
        this.currentSession = currentSession;

        //
        // Container borders
        setBorders(false);
        setBodyBorder(true);
        setHeaderVisible(false);

        //
        // CRUD toolbar
        entityCRUDToolbar = getToolbar();
        if (entityCRUDToolbar != null) {
            setTopComponent(entityCRUDToolbar);
        }
        //
        // Paging toolbar
        entityPagingToolbar = getPagingToolbar();
        if (entityPagingToolbar != null) {
            setBottomComponent(entityPagingToolbar);
        }
    }

    @Override
    protected void onRender(Element target, int index) {
        super.onRender(target, index);

        //
        // Configure Entity Grid

        // Data Proxy
        RpcProxy<PagingLoadResult<M>> dataProxy = getDataProxy();

        // Data Loader
        entityLoader = new BasePagingLoader<PagingLoadResult<M>>(dataProxy);

        // Data Store
        entityStore = new ListStore<M>(entityLoader);

        //
        // Grid Data Load Listener
        entityLoader.addLoadListener(new EntityGridLoadListener<M>(this, entityStore));
        entityLoader.setRemoteSort(true);

        //
        // Bind Entity Paging Toolbar
        if (entityPagingToolbar != null) {
            entityPagingToolbar.bind(entityLoader);
        }

        //
        // Configure columns
        ColumnModel columnModel = new ColumnModel(getColumns());

        //
        // Set grid
        entityGrid = new MyGrid<M>(entityStore, columnModel);
        add(entityGrid);

        //
        // Bind the grid to CRUD toolbar
        entityCRUDToolbar.setEntityGrid(this);

        //
        // Grid selection mode
        GridSelectionModel<M> selectionModel = entityGrid.getSelectionModel();
        selectionModel.setSelectionMode(SelectionMode.SINGLE);
        selectionModel.addSelectionChangedListener(new SelectionChangedListener<M>() {

            @Override
            public void selectionChanged(SelectionChangedEvent<M> se) {
                selectionChangedEvent(se.getSelectedItem());
            }
        });

        //
        // Grid view options
        GridView gridView = entityGrid.getView();
        gridView.setEmptyText(MSGS.gridEmptyResult());

        //
        // Do first load
        refresh();
    }

    protected EntityCRUDToolbar<M> getToolbar() {
        return new EntityCRUDToolbar<M>(currentSession);
    }

    protected abstract RpcProxy<PagingLoadResult<M>> getDataProxy();

    protected PagingToolBar getPagingToolbar() {
        return new MyPagingToolBar(ENTITY_PAGE_SIZE);
    }

    protected abstract List<ColumnConfig> getColumns();

    public void refresh() {
        entityLoader.load();
        entityPagingToolbar.enable();
    }

    public void refresh(GwtQuery query) {
        // m_filterPredicates = predicates;
        setFilterQuery(query);
        entityLoader.load();
        entityPagingToolbar.enable();
    }

    public void setFilterPanel(EntityFilterPanel<M> filterPanel) {
        this.filterPanel = filterPanel;
        entityCRUDToolbar.setFilterPanel(filterPanel);
    }

    protected void selectionChangedEvent(M selectedItem) {
        if (parentEntityView != null) {
            parentEntityView.setSelectedEntity(selectedItem);
        }
    }

    public void setPagingToolbar(PagingToolBar entityPagingToolbar) {
        this.entityPagingToolbar = entityPagingToolbar;
    }

    public GridSelectionModel<M> getSelectionModel() {
        return entityGrid.getSelectionModel();
    }

This is MyGrid class:

public class MyGrid<M extends KapuaBaseModel> extends Grid<M> {

    public MyGridGrid(ListStore<M> store, ColumnModel cm) {
        super(store, cm);

        //
        // Grid properties
        setBorders(false);
        setStateful(false);
        setLoadMask(true);
        setStripeRows(true);
        setTrackMouseOver(false);
        disableTextSelection(false);

        //
        // Grid view options
        GridView gridView = getView();
        gridView.setAutoFill(true);
        gridView.setForceFit(true);
        gridView.setSortingEnabled(false);
    }
}

And this is MyPagingToolbar:

public class MyPagingToolBar extends PagingToolBar {

    private static final ConsoleMessages MSGS = GWT.create(ConsoleMessages.class);

    public MyPagingToolBar(int pageSize) {
        super(pageSize);

        PagingToolBarMessages pagingToolbarMessages = getMessages();
        pagingToolbarMessages.setBeforePageText(MSGS.pagingToolbarPage());
        pagingToolbarMessages.setAfterPageText(MSGS.pagingToolbarOf().concat("{0}"));

        StringBuilder sb = new StringBuilder();
        sb.append(MSGS.pagingToolbarShowingPre())
                .append(" {0} - {1} ")
                .append(MSGS.pagingToolbarShowingMid())
                .append(" {2} ")
                .append(MSGS.pagingToolbarShowingPost());
        pagingToolbarMessages.setDisplayMsg(sb.toString());

        pagingToolbarMessages.setEmptyMsg(MSGS.pagingToolbarNoResult());

        pagingToolbarMessages.setFirstText(MSGS.pagingToolbarFirstPage());
        pagingToolbarMessages.setPrevText(MSGS.pagingToolbarPrevPage());
        pagingToolbarMessages.setNextText(MSGS.pagingToolbarNextPage());
        pagingToolbarMessages.setLastText(MSGS.pagingToolbarLastPage());
        pagingToolbarMessages.setRefreshText(MSGS.pagingToolbarRefresh());
    }
}

I saw some similar questions but that solutions did not work in my case. So please, do not mark this question as duplicate. Thanks in advance.

This is my server method:

 @Override
    public PagingLoadResult<GwtTag> query(PagingLoadConfig loadConfig,
            GwtTagQuery gwtTagQuery) throws GwtKapuaException {
        int totalLength = 0;
        List<GwtTag> gwtTagList = new ArrayList<GwtTag>();
        try {
            KapuaLocator locator = KapuaLocator.getInstance();
            TagService tagService = locator.getService(TagService.class);
            TagQuery tagQuery = GwtKapuaTagModelConverter.convertTagQuery(loadConfig, gwtTagQuery);
            UserService userService = locator.getService(UserService.class);
            TagListResult tags = tagService.query(tagQuery);
            if (!tags.isEmpty()) {
                if (tags.getSize() >= loadConfig.getLimit()) {
                    totalLength = Long.valueOf(tagService.count(tagQuery)).intValue();

                } else {
                    totalLength = tags.getSize();
                }
                for (Tag g : tags.getItems()) {
                    gwtTagList.add(KapuaGwtTagModelConverter.convertTag(g));
                    for (GwtTag gwtTag : gwtTagList) {
                        User user = userService.find(g.getScopeId(), g.getCreatedBy());
                        if (user != null) {
                            gwtTag.setUserName(user.getDisplayName());
                        }
                }
            }
            }
        } catch (Exception e) {
            KapuaExceptionHandler.handle(e);
        }
        return new BasePagingLoadResult<GwtTag>(gwtTagList, loadConfig.getOffset(),
                totalLength);
    }

And this is where I call that query server method :

public class TagGrid extends EntityGrid<GwtTag> {

    private static final GwtTagServiceAsync GWT_TAG_SERVICE = GWT.create(GwtTagService.class);
    private static final ConsoleTagMessages MSGS = GWT.create(ConsoleTagMessages.class);
    private GwtTagQuery query;

    protected TagGrid(AbstractEntityView<GwtTag> entityView, GwtSession currentSession) {
        super(entityView, currentSession);
        query = new GwtTagQuery();
        query.setScopeId(currentSession.getSelectedAccountId());
    }

    @Override
    protected RpcProxy<PagingLoadResult<GwtTag>> getDataProxy() {
        return new RpcProxy<PagingLoadResult<GwtTag>>() {

            @Override
            protected void load(Object loadConfig,
                    AsyncCallback<PagingLoadResult<GwtTag>> callback) {
                GWT_TAG_SERVICE.query((PagingLoadConfig) loadConfig, query, callback);

            }
        };
    }

EDIT: This is convertQuery method

   public static TagQuery convertTagQuery(PagingLoadConfig loadConfig, GwtTagQuery gwtTagQuery) {
        KapuaLocator locator = KapuaLocator.getInstance();
        TagFactory tagFactory = locator.getFactory(TagFactory.class);
        TagQuery tagQuery = tagFactory.newQuery(GwtKapuaCommonsModelConverter.convertKapuaId(gwtTagQuery.getScopeId()));
        if (gwtTagQuery.getName() != null && !gwtTagQuery.getName().isEmpty()) {
            tagQuery.setPredicate(new AttributePredicate<String>(TagPredicates.NAME, gwtTagQuery.getName(), Operator.LIKE));
        }
        tagQuery.setOffset(loadConfig.getOffset());
        tagQuery.setLimit(loadConfig.getLimit());

        return tagQuery;
    }
  • Where is the server code? Are you 100% certain that the server is right? If so, consider also sharing the rest of how you communicate with the server, such as the `getDataProxy()` method, the associated RPC interfaces, etc. – Colin Alworth Nov 03 '17 at 17:39
  • @ColinAlworth I have edited question with server method, please look... – user8881151 Nov 06 '17 at 07:51
  • This appears to have the same code as in https://stackoverflow.com/questions/47030383/why-my-grid-does-not-move-on-second-page-with-paging-toolbargwt-2-4, and suffers from the same issue - nested loops where they shouldn't be, probably broken "total count". The contents of convertTagQuery probably will tell more, but so far you aren't taking the offset and limit into account on the server... – Colin Alworth Nov 06 '17 at 13:50
  • @ColinAlworth I wrote this convertTagQuery method, please take a look, and If you have some code proposal please wrote me...thanks in advance. – user8881151 Nov 06 '17 at 20:54
  • I mean, it shows it copying the values, but clearly you aren't correctly using them on the server. I don't know your server - perhaps look in `tagService.query`? Somewhere, you are failing to handle the offset and limit, or the values are wrong - have you tried logging these and confirming the query is handling them right? – Colin Alworth Nov 06 '17 at 22:29
  • @ColinAlworth Well, these classes which I posted are the only classes in which I implement something for paging toolbar, do you have some code proposal maybe for this server method and how to change my loops? :) – user8881151 Nov 06 '17 at 22:46
  • Didn't we discuss this over email? Also, look at the last question I linked - it has the same code, and in my answer there I made suggestions already about fixing those loops. Stackoverflow is not a great way to get code review - especially since your question is about paging, and not loops or optimization. – Colin Alworth Nov 06 '17 at 22:48
  • That piece of code did not help....I wrote that your suggestion and return new BAsePagingLoader(wtTagList, itemsLeftToSkip,totalLength) but then I have got just empty grid without any item... – user8881151 Nov 06 '17 at 22:52
  • As with your past questions, there isnt enough here to say why that is. You are still using very out-of date GWT and GXT. If you can't share the code publicly or privately, and aren't able to do the required debugging or logging, there isn't much anyone can do to help you... – Colin Alworth Nov 06 '17 at 23:24

0 Answers0