2017-10-31 12 views
0

나는 페이징 툴바를 사용하고있는 GWT 앱을 개발 중이다. 그리드에 10 개 이상의 그룹이 있으면 사용자는 페이징 툴바를 사용하여 두 번째 페이지로 이동할 수 있습니다. 하지만 버튼을 눌러 두 번째 페이지로 이동하면 두 번째 페이지로 이동합니다.로드가 표시되지만 툴바는 첫 페이지로 돌아갑니다. 10 항목. 이 첫 페이지입니다 : enter image description here페이징 툴바 (GWT 2.4)가있는 제 2 페이지에서 그리드가 이동하지 않는 이유는 무엇입니까?

내가 두 번째 페이지에 버튼을 누를 때 나는이 부하를 얻을 :

enter image description here

그러나 그 도구 모음이 첫 페이지에 저를 백업 한 후. 이 페이징 도구 모음에 대한 내 클래스입니다 :

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()); 
    } 
} 

그리고 이것은 내가 MyPagingToolbar 사용하는 경우 클래스 :

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 KapuaGrid<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)); 

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

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

     // 
     // Set grid 
     entityGrid = new KapuaGrid<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(); 
    } 

    protected abstract GwtQuery getFilterQuery(); 

    protected abstract void setFilterQuery(GwtQuery filterQuery); 

내 실수는 무엇입니까?

편집 : 이것은 내 서버 방법 :

int totalLength = 0; 
     List<GwtGroup> gwtGroupList = new ArrayList<GwtGroup>(); 
     try { 
      KapuaLocator locator = KapuaLocator.getInstance(); 
      GroupService groupService = locator.getService(GroupService.class); 
      UserService userService = locator.getService(UserService.class); 
      GroupQuery groupQuery = GwtKapuaAuthorizationModelConverter.convertGroupQuery(loadConfig, 
        gwtGroupQuery); 
      GroupListResult groups = groupService.query(groupQuery); 
      if (!groups.isEmpty()) { 
       if (groups.getSize() >= loadConfig.getLimit()) { 
        totalLength = Long.valueOf(groupService.count(groupQuery)).intValue(); 

       } else { 
        totalLength = groups.getSize(); 
       } 
       for (Group g : groups.getItems()) { 
        gwtGroupList.add(KapuaGwtAuthorizationModelConverter.convertGroup(g)); 
        for (GwtGroup gwtGroup : gwtGroupList) { 
         User user = userService.find(g.getScopeId(), g.getCreatedBy()); 
         if (user != null) { 
          gwtGroup.setUserName(user.getDisplayName()); 
         } 
       } 
      } 
      } 
     } catch (Exception e) { 
      KapuaExceptionHandler.handle(e); 
     } 
     return new BasePagingLoadResult<GwtGroup>(gwtGroupList, loadConfig.getOffset(), 
       totalLength); 
    } 

답변

0

(난 그냥이의 이전 버전을 대답하지 않았다 당신이 그들에 대한 답을 얻을, 또는 사람들이 승리 후 질문을 삭제하지 마십시오? 더 이상 귀하의 질문에 대답하지 마십시오.)

서버가 두 번째 페이지 (오프셋 10)에 대한 요청을 받았지만 첫 번째 페이지에 대해 PagingLoadResult을 반환하면 그 내용이 표시됩니다. 서버가 실제로 두 번째 페이지를 보내고 있는지 확인하십시오 - 응답 객체에서 실제로 다음 페이지 (예에서 10)에 사용 된 오프셋을 보내야합니다. 그렇지 않으면 페이징 툴바는 알 수 없습니다. 사용자가 실제로 어떤 페이지에 있는지.

서버가 요청 오프셋을 고려하고 올바르게 사용 된 매개 변수를 클라이언트에 반환하는지 확인하십시오. 올바른 것으로 보이는 경우 질문에 서버 방법을 추가하고 요청한 내용과 반환되는 내용을 확인하기 위해 클라이언트와 서버에 로깅을 추가하십시오.


자바에서 항목을 건너 뛰는 것은 매우 간단하지만 거대한 목록의 경우 확장되지 않습니다.

간단히 말해서 루핑 할 때 첫 번째 offset 항목을 건너 뜁니다.

우선하지만, 무료로 코드 리뷰 - 이것은 매우 비효율적 인 코드입니다 - 당신이 뭔가 추가하면 gwtGroupList의 모든 시간을 모든 항목을 다시 작성됩니다

  for (Group g : groups.getItems()) { 
       gwtGroupList.add(KapuaGwtAuthorizationModelConverter.convertGroup(g)); 
       for (GwtGroup gwtGroup : gwtGroupList) { 
        User user = userService.find(g.getScopeId(), g.getCreatedBy()); 
        if (user != null) { 
         gwtGroup.setUserName(user.getDisplayName()); 
        } 
      } 

대신 읽을 수 :

  for (Group g : groups.getItems()) { 
       gwtGroupList.add(KapuaGwtAuthorizationModelConverter.convertGroup(g)); 
      } 
      for (GwtGroup gwtGroup : gwtGroupList) { 
       User user = userService.find(g.getScopeId(), g.getCreatedBy()); 
       if (user != null) { 
        gwtGroup.setUserName(user.getDisplayName()); 
       } 
      } 

을 또는 하나의 루프 일 수도 있습니다.

이제 우리는 offsetlimit 처리하기 위해, 다시 수정 : 우리가 새 페이지에 필요한 것들에 도달 할 때까지 항목을 방지하기 위해 offset을 사용하는 방법

  int itemsLeftToSkip = offset; 
      for (Group g : groups.getItems()) { 
       if (itemsLeftToSkip > 0) { 
        itemsLeftToSkip--; 
        continue;//we skipped this item, and now the count is one less 
       } 
       if (gwtGroupList.size() >= limit) { 
        break;//we've got enough already, quit the loop 
       } 
       gwtGroupList.add(KapuaGwtAuthorizationModelConverter.convertGroup(g)); 
      } 
      for (GwtGroup gwtGroup : gwtGroupList) { 
       User user = userService.find(g.getScopeId(), g.getCreatedBy()); 
       if (user != null) { 
        gwtGroup.setUserName(user.getDisplayName()); 
       } 
      } 

공지 사항, 우리는에 limit를 사용 오직 그 시간을 최대로 보내십시오.

마지막으로 groupQuery에 이미 제한이 내장되어 있지 않은 경우 (이 경우 오프셋을 입력해야합니다 ...) 이미 코드를로드 했으므로 if (groups.getSize() >= loadConfig.getLimit()) { 코드 블록은 전혀 필요하지 않습니다. 모든 아이템. 제한이 있기 때문에 필요하면 페이지가 끝까지 제대로로드되지 않습니다. 어느 쪽이든,이 코드를 조사하고, 아마도 그것을 더 검토하게 만들면, 그곳에서 매우 잘못된 것처럼 보일 것입니다.

+0

나는 서버 메서드로 질문을 편집했습니다. 제발 .. – Atenica

+0

제안 된 것처럼 서버 메서드는 적어도 붙여 넣은 코드에는 오프셋을 사용하지 않습니다. 'GwtKapuaAuthorizationModelConverter.convertGroupQuery'가 내부적으로 그 일을하고있을 가능성이 있지만, 한계를 올바르게 처리하지 못하기 때문에 이것이 사실이 아닌지 의심 스럽습니다. 오프셋을 사용하여 항목을 제한하기 전에 건너 뜁니다. 가장 좋은 방법은 데이터베이스에서 무언가를 수행하여로드를 시작하지 않는 것입니다. –

+0

오프셋을 사용하여이 방법으로 무엇인가 할 수 있습니까? – Atenica