2012-02-16 5 views
0

TabLayoutPanel과 CellTable을 포함하는 CrawlerOne.java를 호출하는 탭 중 하나에 EntryPoint 클래스 인 WebCrawlerOne.java가 있습니다. 나는 많은 시도를했지만 어떤 오류라도 찾을 수 없습니다. 관련 주제를 검색하려고했지만 프로젝트가 실행될 때 CellTable이 TabLayoutPanel에 표시되지 않습니다.TabLayoutPanel에서 CellTable을 볼 수 없습니다.

  1. 내가 .gwt-TabLayoutPanel와 같은 CSS에서 TabLayoutPanel의 높이를 지정
  2. GWT 2.2.4
  3. 를 사용하여 (DOCTYPE html로 사용) 표준 모드에서 오전 { 높이 : 100 %; }

    CrawlerOne.ui.xml이 g 내부 그때 엔 같습니다 HTMLpanel 태그

    Hello, 
    <g:Button styleName="{style.important}" ui:field="button" /> 
    <table cellspacing='0' cellpadding='0' style='width:100%;'> 
        <tr> 
         <td valign='top'> 
          <c:CellTable addStyleNames="{style.cellTable}" ui:field="table"/> 
         </td> 
        </tr> 
    </table>  
    
    <g:TextBox ui:field="box"></g:TextBox> 
    <g:Button ui:field="addSite"></g:Button> 
    

CrawlerOne.java는

public class CrawlerOne extends Composite implements HasText { 

interface CrawlerOneUiBinder extends UiBinder<Widget, CrawlerOne> { 
} 

@UiField 
CellTable<Contact> table; 

@UiField 
Button addSite; 

@UiField 
TextBox box; 

public CrawlerOne() { 
    Widget w = new Widget(); 
    w = onInitialize(); 
    initWidget(w);  
} 

@UiField 
Button button; 

@UiHandler("button") 
void onClick(ClickEvent e) { 
    Window.alert("Hello!"); 
} 

public void setText(String text) { 
    button.setText(text); 
} 

public String getText() { 
    return button.getText(); 
} 

/** 
    * A simple data type that represents a contact with a unique ID. 
    */ 
    private static class Contact { 
    private static int nextId = 0; 
    private final int id; 

    private String site; 
    private String document; 
    private String pending; 

    public Contact(String site, String document, String pending) { 
     nextId++; 
     this.id = nextId; 
     this.site = site; 
     this.document = document; 
     this.pending = pending; 
    } 

    public String getDocument() { 
     return document; 
    } 

    public int getId() { 
     return id; 
    } 

    public String getSite() { 
     return site; 
    } 

    public void setSite(String site) { 
     this.site = site; 
    } 

    public String getPending() { 
     return pending; 
    } 
    } 

    /** 
    * The list of data to display. 
    */ 
private static final List<Contact> CONTACTS = new LinkedList<Contact>(Arrays.asList(
     new Contact("www.google.com", "12", "123"), 
     new Contact("www.yahoo.com", "23", "124"), 
     new Contact("www.rediff.com", "24", "124"), 
     new Contact("www.gmail.com", "23", "124"), 
     new Contact("www.facebook.com", "23", "124"), 
     new Contact("www.flickr.com", "23", "124"), 
     new Contact("www.youtube.com", "45", "125"))); 

private static final ProvidesKey<Contact> KEY_PROVIDER = 
     new ProvidesKey<Contact>() { 
     @Override 
     public Object getKey(Contact object) { 
      return object.getId(); 
     } 
     }; 

    /** 
    * Initialize. 
    */ 
     public Widget onInitialize() { 
     table = new CellTable<Contact>(KEY_PROVIDER); 
     table.setWidth("100%", true); 
     table.setKeyboardSelectionPolicy(KeyboardSelectionPolicy.ENABLED); 

     initTableColumns(); 

     // Push the data into the widget. 
     table.setRowData(CONTACTS); 

     // Set table width. 
     table.setWidth("100%"); 

     box = new TextBox(); 
     box.setText("Enter New Site"); 

     addSite = new Button("Add Row"); 
     addSite.addClickHandler(new ClickHandler() { 

      @UiHandler("addSite") 
      public void onClick(ClickEvent event) { 
       // TODO Auto-generated method stub 
       try { 
        if(box.getValue()=="") { 
         Window.alert("Error: Invalid Site Value"); 
         box.setText("Enter New Site"); 
        } 
        else { 
         CONTACTS.add(new Contact(box.getValue(), "23", "127")); 
         table.setRowCount(CONTACTS.size(), true); 
         table.setRowData(CONTACTS); 
         table.redraw(); 
        } 
       }catch (Exception e) { 
        Window.alert("Exception Error: " + e); 
       } 
      } 
     }); 

    // Create the UiBinder. 
     CrawlerOneUiBinder uiBinder = GWT.create(CrawlerOneUiBinder.class); 
     Widget widget = uiBinder.createAndBindUi(this); 

     return widget; 
    } 

private void initTableColumns() { 

    //code to add columns 
}}//end of file 
그때 엔 본다 출력은의 EntryPoint 클래스에서 직접 실행하는 경우 enter image description here

그때 엔 CellTable가 표시되어 보이는

public class WebCrawlerOne implements EntryPoint { 
    /** 
    * This is the entry point method. 
    */ 
    public void onModuleLoad() { 
     TabLayoutPanel menu = new TabLayoutPanel(10, Unit.EM); 

     menu.add(new CrawlerOne(), "Crawler"); 
     menu.add(new HTML("This is my page!"), "Page 2"); 
     menu.selectTab(0); 
     RootLayoutPanel.get().add(menu); 
    } 
    } 

그때 엔3210

및 WebCrawlerOne.java 보인다. 어떤 도움을 주셔서 감사합니다. 감사!

답변

2

나는 간단한 대답을 깨닫기 전에 약간의 글을 썼다. 나는 당신이 실제로 필요하다고 생각하기 때문에 먼저 간단한 대답을 고려해야한다.

ui.xml 파일에 CellTable의 새 인스턴스를 만듭니다. 이미 구성한 CellTable 인스턴스를 onInitialize으로 바꾸고 있습니다. 즉, 열이 없으므로 표시되지 않습니다. uibinder.createAndBind에 대한 전화는 이미 제공 한 것으로 표시하지 않는 한 @UiField 개의 주석으로 모든 위젯을 작성합니다. 두 가지 옵션 :

  • 마크 그것을 제공 등 :

    @UiField(provided = true) 
    CellTable<Contact> table; 
    
  • uibinder.createAndBind

    //... 
    Widget widget = uiBinder.createAndBindUi(this); 
    table.setWidth("100%", true); 
    table.setKeyboardSelectionPolicy(KeyboardSelectionPolicy.ENABLED); 
    
    initTableColumns(); 
    
    // Push the data into the widget. 
    table.setRowData(CONTACTS); 
    
    // Set table width. 
    table.setWidth("100%"); 
    

이 첫 번째 옵션은 아마 더 호출 될 때까지 후 테이블을 구성하지 마십시오, 그리기 전에 완전히 구성 할 수 있습니다. 즉, 나는 테스트하지 않았다. (테스트하기 쉽도록 코드가 충분하지 않다.)


다양한 LayoutPanels (일반적으로 구현하는 것을 ProvidesResize 및 RequiresResize) 각자가 가지고 어떤 특정 규칙에 따라 크기 아이들.

크기 조절은 HTMLPanel과 같은 크기 조정을 필요로하지 않는 자식을 지정하면 배치 작업을 수행하지 않고 대신 크기가 적당하지만 크기가 맞을 것으로 예상합니다.

그래서 ui.xml 파일에 그린 HtmlPanel과 html은 TabLayoutPanel이 레이아웃 정보를 CellTable로 올바르게 전달할 수있게 해줍니다. 레이아웃 물건을 사용하고 싶지 않다면, 이것은 좋은 일입니다. CellTable의 크기를 다른 방식으로 조정해야합니다.

마지막으로 한 가지 생각 : FireBug 등을 사용하여 dom이 예상대로 설정되어 있는지 확인하십시오. 거기에 셀 테이블이 있지만 내용이 없다는 것을 알 수 있습니다.

+0

정말 고마워요! @UiField (제공된 = true)가 누락되었습니다. 나는 다른 버그로 인해 이전에 그것을 제거했다가 다시 놓는 것을 잊어 버렸다. 고마워요! :) – Prince

관련 문제