2014-03-18 2 views
1

제 애플리케이션에서 pageableListView와 propertyListView를 결합해야합니다. 왜 그냥 pageableListView does not 모델이나 목록없이 생성자를 가지고 궁금해. 나는 단지 propertyListView를 확장하고 pageableListView를 가진 body와 string = id와 행의 수만 갖는 추가 생성자를 생성하는 새로운 클래스를 생성한다. 이제는보기 좋고 작동합니다. 이 때가끔 작동하지 않는 것을 놓쳤습니까?PageableListView에 모델 또는 목록이없는 생성자가없는 이유

package org.toursys.web.components; 

import java.util.List; 

import org.apache.wicket.markup.html.list.ListView; 
import org.apache.wicket.markup.html.list.PropertyListView; 
import org.apache.wicket.model.IModel; 

public abstract class PropertyPageableListView<T> extends PropertyListView<T> implements IPageableItems { 
    private static final long serialVersionUID = 1L; 

    /** The page to show. */ 
    private int currentPage; 

    /** Number of rows per page of the list view. */ 
    private int itemsPerPage; 

    /** 
    * Constructor 
    * 
    * @param id 
    *   See Component 
    * @param model 
    *   See Component 
    * @param itemsPerPage 
    *   Number of rows to show on a page 
    */ 
    public PropertyPageableListView(final String id, int itemsPerPage) { 
     super(id); 
     this.itemsPerPage = itemsPerPage; 
    } 

    /** 
    * Constructor 
    * 
    * @param id 
    *   See Component 
    * @param model 
    *   See Component 
    * @param itemsPerPage 
    *   Number of rows to show on a page 
    */ 
    public PropertyPageableListView(final String id, final IModel<? extends List<? extends T>> model, int itemsPerPage) { 
     super(id, model); 
     this.itemsPerPage = itemsPerPage; 
    } 

    /** 
    * Creates a pageable list view having the given number of rows per page that uses the provided object as a simple 
    * model. 
    * 
    * @param id 
    *   See Component 
    * @param list 
    *   See Component 
    * @param itemsPerPage 
    *   Number of rows to show on a page 
    * @see ListView#ListView(String, List) 
    */ 
    public PropertyPageableListView(final String id, final List<? extends T> list, final int itemsPerPage) { 
     super(id, list); 
     this.itemsPerPage = itemsPerPage; 
    } 

    /** 
    * Gets the index of the current page being displayed by this list view. 
    * 
    * @return Returns the currentPage. 
    */ 
    public final int getCurrentPage() { 
     // If first cell is out of range, bring page back into range 
     while ((currentPage > 0) && ((currentPage * itemsPerPage) >= getItemCount())) { 
      currentPage--; 
     } 

     return currentPage; 
    } 

    /** 
    * Gets the number of pages in this list view. 
    * 
    * @return The number of pages in this list view 
    */ 
    public final int getPageCount() { 
     return ((getItemCount() + itemsPerPage) - 1)/itemsPerPage; 
    } 

    /** 
    * Gets the maximum number of rows on each page. 
    * 
    * @return the maximum number of rows on each page. 
    */ 
    public final int getItemsPerPage() { 
     return itemsPerPage; 
    } 

    /** 
    * Sets the maximum number of rows on each page. 
    * 
    * @param itemsPerPage 
    *   the maximum number of rows on each page. 
    */ 
    public final void setItemsPerPage(int itemsPerPage) { 
     if (itemsPerPage < 0) { 
      itemsPerPage = 0; 
     } 

     addStateChange(); 
     this.itemsPerPage = itemsPerPage; 
    } 

    /** 
    * @return offset of first item 
    */ 
    public int getFirstItemOffset() { 
     return getCurrentPage() * getItemsPerPage(); 
    } 

    /** 
    * @see org.apache.wicket.markup.html.navigation.paging.IPageableItems#getItemCount() 
    */ 
    public int getItemCount() { 
     return getList().size(); 
    } 

    /** 
    * @see org.apache.wicket.markup.html.list.ListView#getViewSize() 
    */ 
    @Override 
    public int getViewSize() { 
     if (getDefaultModelObject() != null) { 
      super.setStartIndex(getFirstItemOffset()); 
      super.setViewSize(getItemsPerPage()); 
     } 

     return super.getViewSize(); 
    } 

    /** 
    * Sets the current page that this list view should show. 
    * 
    * @param currentPage 
    *   The currentPage to set. 
    */ 
    public final void setCurrentPage(int currentPage) { 
     if (currentPage < 0) { 
      currentPage = 0; 
     } 

     int pageCount = getPageCount(); 
     if ((currentPage > 0) && (currentPage >= pageCount)) { 
      currentPage = pageCount - 1; 
     } 

     addStateChange(); 
     this.currentPage = currentPage; 
    } 

    /** 
    * Prevent users from accidentally using it. 
    * 
    * @see org.apache.wicket.markup.html.list.ListView#setStartIndex(int) 
    * @throws UnsupportedOperationException 
    *    always 
    */ 
    @Override 
    public ListView<T> setStartIndex(int startIndex) throws UnsupportedOperationException { 
     throw new UnsupportedOperationException("You must not use setStartIndex() with PageableListView"); 
    } 

    /** 
    * Prevent users from accidentally using it. 
    * 
    * @param size 
    *   the view size 
    * @return This 
    * @throws UnsupportedOperationException 
    *    always 
    * @see org.apache.wicket.markup.html.list.ListView#setStartIndex(int) 
    */ 
    @Override 
    public ListView<T> setViewSize(int size) throws UnsupportedOperationException { 
     throw new UnsupportedOperationException("You must not use setViewSize() with PageableListView"); 
    } 

} 

답변

0

당신이 PageableListView을 확장하고 그냥 PropertyListView처럼 작동하게하는 하나의 방법을 추가 할 수 쉬울 것 :

/** 
* Wraps a ListItemModel in a CompoundPropertyModel. 
* 
* @param model 
* @param index 
* @return a CompoundPropertyModel wrapping a ListItemModel 
*/ 
@Override 
protected IModel<T> getListItemModel(final IModel<? extends List<T>> model, final int index) 
{ 
    return new CompoundPropertyModel<T>(super.getListItemModel(model, index)); 
} 

당신도 추가 생성자에 대한 RFE를 제기 할 수 있습니다.

관련 문제