gwt
  • gwtbootstrap3
  • 2015-02-23 25 views 1 likes 
    1

    我想在gwt-bootstrap3模態中添加一些元素[link],我正在使用UI-binder生成屏幕,但沒有任何內容出現。如何在gwt-bootstrap3中添加表單元素

    我的UI粘合劑類

    <?xml version="1.0" encoding="UTF-8"?> 
    <ui:UiBinder xmlns:ui='urn:ui:com.google.gwt.uibinder' xmlns:g='urn:import:com.google.gwt.user.client.ui' xmlns:b='urn:import:org.gwtbootstrap3.client.ui' 
    xmlns:res="urn:with:com.db.cary.client.resources.CSSResources"> 
        <ui:with type="com.db.cary.client.resources.CSSResources" field="res"> 
        </ui:with> 
        <b:Modal closable="true" fade="true" dataBackdrop="TRUE" dataKeyboard="true"> 
         <b:ModalBody> 
          <b:Form type="HORIZONTAL"> 
           <b:FieldSet> 
            <b:Legend>Please enter the book detail</b:Legend> 
    
            <b:FormGroup> 
             <b:FormLabel for="bookTitle" addStyleNames="col-lg-2">Title</b:FormLabel> 
             <g:FlowPanel addStyleNames="col-lg-10"> 
              <b:TextBox placeholder="Enter book Title" ui:field="titleTextBox" /> 
             </g:FlowPanel> 
            </b:FormGroup> 
    
            <b:FormGroup> 
             <b:FormLabel for="bookAuthor" addStyleNames="col-lg-2">Author</b:FormLabel> 
             <g:FlowPanel addStyleNames="col-lg-10"> 
              <b:ListBox ui:field="authorListBox" /> 
              <b:Button ui:field="newAuthorButton" type="LINK" size="EXTRA_SMALL">New author</b:Button> 
             </g:FlowPanel> 
             <g:FlowPanel addStyleNames="col-lg-offset-2 col-lg-10"> 
              <b:TextBox ui:field="authorTextBox" placeholder="enter slash (/) separated list of authors"></b:TextBox> 
             </g:FlowPanel> 
            </b:FormGroup> 
    
            <b:FormGroup> 
             <b:FormLabel for="bookCategory" addStyleNames="col-lg-2">Category</b:FormLabel> 
             <g:FlowPanel addStyleNames="col-lg-10"> 
              <b:ListBox ui:field="categoryListBox" /> 
              <b:Button ui:field="newCategoryButton" type="LINK" size="EXTRA_SMALL">New Category</b:Button> 
             </g:FlowPanel> 
             <g:FlowPanel addStyleNames="col-lg-offset-2 col-lg-10"> 
              <b:TextBox ui:field="categoryTextBox" placeholder="enter category"></b:TextBox> 
             </g:FlowPanel> 
            </b:FormGroup> 
           </b:FieldSet> 
          </b:Form> 
         </b:ModalBody> 
         <b:ModalFooter> 
          <b:Button type="PRIMARY" ui:field='submitButton'>Submit</b:Button> 
          <b:Button ui:field='cancelButton'>Cancel</b:Button> 
         </b:ModalFooter> 
        </b:Modal> 
    </ui:UiBinder> 
    

    和我的視圖類

    public class AddBook extends Modal { 
    
        interface CheckOutPopUpBinder extends UiBinder<Widget, AddBook> { 
        } 
    
        private static final CheckOutPopUpBinder binder = GWT.create(CheckOutPopUpBinder.class); 
        private final AuthorAndCategoryServiceAsync authorService = GWT.create(AuthorAndCategoryService.class); 
        private final LibraryServiceAsync libraryServiceAsync = GWT.create(LibraryService.class); 
    
        @UiField 
        TextBox titleTextBox; 
        @UiField 
        ListBox authorListBox; 
        @UiField 
        TextBox authorTextBox; 
        @UiField 
        ListBox categoryListBox; 
        @UiField 
        Button submitButton; 
        @UiField 
        Button cancelButton; 
    
        @UiField 
        Button newAuthorButton; 
        @UiField 
        Button newCategoryButton; 
        @UiField 
        TextBox categoryTextBox; 
    
        public AddBook(String title) { 
         binder.createAndBindUi(this); 
         setTitle(title); 
         initializeAuthorListBox(); 
         initializeCategoryListBox(); 
        } 
    
        private void initializeCategoryListBox() { 
         authorService.getCategories(null, new AsyncCallback<List<CategoryDTO>>() { 
    
        @Override 
        public void onFailure(Throwable arg0) { 
         Window.alert("unable to fetch category list"); 
        } 
    
        @Override 
        public void onSuccess(List<CategoryDTO> arg0) { 
         for (CategoryDTO category : arg0) 
          categoryListBox.addItem(category.getCategoryName()); 
        } 
         }); 
         categoryListBox.setMultipleSelect(false); 
         categoryTextBox.setVisible(false); 
    
        } 
    
        private void initializeAuthorListBox() { 
         authorService.getAuthors(null, new AsyncCallback<List<AuthorDTO>>() { 
        @Override 
        public void onSuccess(List<AuthorDTO> arg0) { 
         for (AuthorDTO author : arg0) { 
          authorListBox.addItem(author.getAuthorName()); 
         } 
        } 
    
        @Override 
        public void onFailure(Throwable arg0) { 
         Window.alert("Unable to fetch the list of authors"); 
        } 
         }); 
         authorListBox.setMultipleSelect(true); 
         authorTextBox.setVisible(false); 
        } 
    
        @UiHandler("cancelButton") 
        public void cancelAction(ClickEvent e) { 
         AddBook.this.hide(); 
        } 
    
        @UiHandler("submitButton") 
        public void submitAction(ClickEvent e) { 
         AddBookDTO bookDTO = new AddBookDTO(); 
         String bookTitle = titleTextBox.getText(); 
         String bookCategory = categoryListBox.getSelectedValue() == null ? categoryTextBox.getText() : categoryListBox.getSelectedValue(); 
         List<String> authorsList = new ArrayList<String>(); 
    
         for (int i = 0; i < authorListBox.getItemCount(); i++) { 
        if (authorListBox.isItemSelected(i)) { 
         authorsList.add(authorListBox.getItemText(i)); 
        } 
         } 
    
         if (null != authorTextBox.getText() && authorTextBox.getText().trim().length() > 0) { 
        String[] values = authorTextBox.getText().split("/"); 
        for (String str : values) { 
         authorsList.add(str); 
        } 
         } 
         if (bookTitle == null || bookTitle.length() <= 0) { 
        Window.alert("Please enter a valid book title"); 
        return; 
         } else if (bookCategory == null || bookCategory.length() <= 0) { 
        Window.alert("Please enter a valid book category"); 
        return; 
         } else if (authorsList == null || authorsList.size() == 0) { 
        Window.alert("Please enter valid authors"); 
        return; 
         } 
         bookDTO.setBookTitle(bookTitle); 
         bookDTO.setCategroyName(bookCategory); 
         bookDTO.setAuthors(authorsList); 
         libraryServiceAsync.addBook(bookDTO, new AsyncCallback<Boolean>() { 
    
        @Override 
        public void onFailure(Throwable arg0) { 
         Window.alert("There is some issue with database while adding book, Please contact your admin"); 
    
        } 
    
        @Override 
        public void onSuccess(Boolean arg0) { 
         Window.alert("Book is successfully added !!!"); 
        } 
         }); 
         this.hide(); 
    
        } 
    
        @UiHandler("newAuthorButton") 
        public void addAuthor(ClickEvent e) { 
         authorTextBox.setVisible(true); 
        } 
    
        @UiHandler("newCategoryButton") 
        public void addCategory(ClickEvent e) { 
         categoryTextBox.setVisible(true); 
        } 
    
    } 
    

    我不知道,什麼是錯的,但只有頭出現在模態。

    回答

    1

    您正在致電AddBook.this.show(); - 這顯示實例的基礎Modal,而不是您的UiBinder模板中定義的實例。當您致電setTitle(title);時,您正在設置此實例的標題/標題 - 這就是您看到的只是標題而不是模態其餘部分的原因。您應該爲您的UiBinder模板中定義的Modal指定ui:field並顯示/隱藏它。

    而且AddBook不應該被擴展Modal - 它不應該延長任何部件類在所有:)通常情況下,UiBinder的類擴展Composite - 因爲你的UiBinder的模板是由各種小部件和Composite用來把他們在一起而不會暴露他們的任何API:您致電initWidget,結果爲binder.createAndBindUi(this)。 但是,如果您要創建一個其「主」小工具爲Modal的小工具,就像這裏一樣,您應該只需撥打binder.createAndBindUi(this)並忽略返回的Widget(就像您現在所做的那樣)。這是因爲Modal將自己附加到DOM,繞過了任何GWT機制(實際上,它與它衝突)。

    相關問題