2016-07-14 2 views
1

정보를로드하기 위해 지연로드를 사용하는 테이블의 예를 찾으려고합니다. 나는 좋은 모습을 보였지만 아무데도 좋은 예를 찾을 수있는 것 같지 않습니다. (나는 Viritin과 같은 것을 사용하고 싶지 않습니다.) 저는 처음부터 그것을하고 싶습니다. vaadin 웹 사이트의 문서는 실제로 Table을 도와주지 않으므로 수행해야 할 작업에 대해 설명하는 좋은 자습서를 알고 있는지 궁금합니다. 아마도 그 예가 더 좋을 수도 있습니다. 여기에 최대 5000 개의 정수를 표시하는 간단한 테이블이 있습니다. 여기에 아주 간단한 응용 프로그램 인 느린 로딩을 구현하려고합니다. 그런 다음 내 자신의 응용 프로그램에서 쉽게 기능을 통합 할 수 있기를 바랍니다. 여기에 코드가 있습니다. 내 UI 클래스 (MyUI.java) :vaadin의 지연로드 테이블

public class MyUI extends UI { 

    @Override 
    protected void init(VaadinRequest vaadinRequest) { 
     final VerticalLayout layout = new VerticalLayout(); 
     numberTable theTable = new numberTable(); 


     Button button = new Button("Click Me"); 
     button.addClickListener(new Button.ClickListener() 
     { 

      @Override 
      public void buttonClick(ClickEvent event) 
      { 
       System.out.println("test!"); 

      } 
     }); 

     layout.addComponents(button, theTable); 
     layout.setMargin(true); 
     layout.setSpacing(true); 

     setContent(layout); 
    } 

그리고 테이블 클래스 (numberTable.java) : 나는 게으른 로딩 기능을 구현하는 것을 읽었습니다

package my.vaadin.project.tableTest; 

import com.vaadin.ui.Table; 

public class numberTable extends Table 
{ 
    public numberTable(){ 
     /*addContainerProperty("Name", String.class, null); 
     addContainerProperty("Mag", Float.class, null); 
     addItem(new Object[]{"Canopus",  -0.72f}, 1); 
     addItem(new Object[]{"Arcturus",  -0.04f}, 2); 
     addItem(new Object[]{"Alpha Centauri", -0.01f}, 3);*/ 
     addContainerProperty("Number", Integer.class, null); 
     for(int i=1; i<=5000; i++){ 
      Integer itemID = new Integer(i); 
      addItem(new Object[]{i},itemID); 
     } 
     setCaption("Rendering table"); 
     addStyleName("testTable"); 
     setPageLength(size()); 
     System.out.println("table created"); 
    } 

} 

은 내가 있어야 테이블을 지원하는 컨테이너, 그건 내 이해입니다.

+0

어떤 종류의 데이터 소스가 있습니까? Vaadin의 일부 컨테이너는 게으른로드를 지원합니다. –

+0

안녕 테이블 (테이블을 확장하는 클래스에서 만든) – antobbo

+0

테이블 컨테이너에서 데이터를 표시하는 방법입니다. 표를 어떻게 채우고 있습니까? https://vaadin.com/docs/-/part/framework/components/components-table.html. 테이블이 필요에 따라 컨테이너에서 행을 검색합니다. –

답변

1

documentation에 따르면 IndexedContainer이 사용자의 요구 사항과 일치합니다. 또는 Table으로 지연로드를 지원하는 컨테이너를 직접 구현하려는 경우 Container.Indexedinterface을 구현하십시오. 예를 들어 IndexedContainer 소스 코드를 검색 할 수 있습니다.

은 내가 Container.Indexed 인터페이스를 구현하는 기본 예제를 만들었습니다 :

public class MyContainer implements Container.Indexed { 

    public Object nextItemId(Object itemId) { return ((Integer) itemId) + 1; } 
    public Object prevItemId(Object itemId) { return ((Integer) itemId) - 1; } 
    public Object firstItemId() { return 0; } 
    public Object lastItemId() { return 5000; } 
    public boolean isFirstId(Object itemId) { return Integer.valueOf(0).equals(itemId); } 
    public boolean isLastId(Object itemId) { return Integer.valueOf(5000).equals(itemId); } 

    public Item getItem(Object itemId) { 
     PropertysetItem item = new PropertysetItem(); 
     item.addItemProperty("index", new ObjectProperty<Integer>((Integer) itemId)); 
     return item; 
    } 
    public Collection<?> getContainerPropertyIds() { return Arrays.asList("index"); } 
    public Collection<?> getItemIds() { return Arrays.asList(IntStream.range(0, 5001).boxed().toArray(Integer[]::new)); } 
    public Property getContainerProperty(Object itemId, Object propertyId) { return new ObjectProperty<Integer>((Integer) itemId); } 
    public Class<?> getType(Object propertyId) { return Integer.class; } 
    public int size() { return 5001; } 
    public boolean containsId(Object itemId) { 
     Integer item = (Integer) itemId; 
     return item >= 0 && item <= 5000; 
    } 
    public int indexOfId(Object itemId) { return (Integer) itemId; } 
    public Object getIdByIndex(int index) { return index; } 
    public List<?> getItemIds(int startIndex, int numberOfItems) { return Arrays.asList(IntStream.range(0, 5001).boxed().toArray(Integer[]::new)).subList(startIndex, startIndex + numberOfItems); } 

    public Item addItem(Object itemId) throws UnsupportedOperationException { throw new UnsupportedOperationException(); } 
    public Object addItem() throws UnsupportedOperationException { throw new UnsupportedOperationException(); } 
    public boolean removeItem(Object itemId) throws UnsupportedOperationException { throw new UnsupportedOperationException(); } 
    public boolean addContainerProperty(Object propertyId, Class<?> type, Object defaultValue) throws UnsupportedOperationException { throw new UnsupportedOperationException(); } 
    public boolean removeContainerProperty(Object propertyId) throws UnsupportedOperationException { throw new UnsupportedOperationException(); } 
    public boolean removeAllItems() throws UnsupportedOperationException { throw new UnsupportedOperationException(); } 
    public Object addItemAfter(Object previousItemId) throws UnsupportedOperationException { throw new UnsupportedOperationException(); } 
    public Item addItemAfter(Object previousItemId, Object newItemId) throws UnsupportedOperationException { throw new UnsupportedOperationException(); } 
    public Object addItemAt(int index) throws UnsupportedOperationException { throw new UnsupportedOperationException(); } 
    public Item addItemAt(int index, Object newItemId) throws UnsupportedOperationException { throw new UnsupportedOperationException(); } 

} 

그것은 읽기 전용입니다. 항목에는 0 ~ 5000 사이의 항목의 인덱스 인 하나의 속성 "indexed" 만 있습니다. 보시다시피, 그것은 많은 작업이므로 가능한 경우 내장 컨테이너를 사용해야합니다.

+0

. 나는 약간 흥미로운 것을 알아 차렸다. 내 자신의 예제 코드에서. 테이블의 모든 요소를 ​​표시하므로'setPageLength (size());'를'setPageLength (100);'으로 변경했습니다. 그리고 게으른 로딩이 작동합니다. 테이블에 게으른 로딩이 있음을 의미합니까? 유일한 것은 비록 내가 내 자신의 응용 프로그램에 적용 할 때 (나는 테이블 행이지만 객체에 정수가 없음) 게으른 로딩이 작동 할 때까지 아래로 스크롤 할 때 괜찮지 만 다시 위로 스크롤하면 일부 테이블 행이 비어있는 것입니다 – antobbo

+0

이상한 소리, 아마도 버그, 코드 없이는 말할 수 없습니다. –

+0

글쎄요, 당신이 그것에 대해 생각한다면 말입니다. 'setPageLength (size());'는 기본적으로 모든 행을 표시한다고 말하고 있으므로,'setPageLength (100);가있는 곳에서는 모든 것이 있기 때문에 게으른 로딩을 할 수 없다. 다른 것들은 느린 로딩을 통해로드됩니다 (제공되는대로 제공됩니다). 코드는 내가 스레드를 업데이트 한 방식대로 포함되어 있습니다. – antobbo

관련 문제