2

我正在尝试使用 GWT-Bootstrap 模式小部件创建一个对话框。我可以让它显示,但无法让按钮识别事件。onClick 的取消按钮永远不会触发。有一些其他代码试图让 addClass 按钮做一些事情,但把它去掉了。如果我可以让取消按钮做某事(任何事情!),我应该状态良好。

我也尝试过使用 addDomHandler 的java,但也没有用。

这是 XML:

<!DOCTYPE ui:UiBinder SYSTEM "http://dl.google.com/gwt/DTD/xhtml.ent">
<ui:UiBinder xmlns:ui="urn:ui:com.google.gwt.uibinder"
  xmlns:a="urn:import:cgs.common.client.gwt.bootstrap"
  xmlns:b="urn:import:com.github.gwtbootstrap.client.ui"
  xmlns:g="urn:import:com.google.gwt.user.client.ui">
  <b:Modal title="Add Class?" ui:field="addClassModal" backdrop="STATIC" keyboard="true" animation="true">
    <a:BootstrapField label="Classname:">
     <a:BootstrapTextInput
          ui:field="classname" 
          placeholder="Classname" />
        </a:BootstrapField>
    <b:Button ui:field="addClass">Add Class</b:Button>
    <b:Button ui:field="cancel">Cancel</b:Button>
    </b:Modal>
</ui:UiBinder> 

这是java:

package cgs.teacher.portal.client.view.impl.bootstrap;


import cgs.common.client.gwt.bootstrap.BootstrapTextInput;

import com.github.gwtbootstrap.client.ui.Button;
import com.github.gwtbootstrap.client.ui.Modal;
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;

import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.Widget;



public class AddClassDialogViewImpl
        extends Composite

{


    interface AddClassDialogViewImplUiBinder extends UiBinder<Widget, AddClassDialogViewImpl>
    {
    }

    private static AddClassDialogViewImplUiBinder uiBinder = GWT
            .create(AddClassDialogViewImplUiBinder.class);

    @UiField
    Modal addClassModal;
    @UiField
    BootstrapTextInput classname;
    @UiField
    Button addClass;
    @UiField
    Button cancel;



    public AddClassDialogViewImpl()
    {
        initWidget(uiBinder.createAndBindUi(this));



        cancel.addClickHandler(new ClickHandler() {
            @Override
            public void onClick(ClickEvent event) {
              addClassModal.hide();
            }
          });

        addClassModal.toggle();  //PS. Show gave error. Had to use toggle to show!

    }

}

谢谢!

4

1 回答 1

0

我发现的另一个解决方法是将 Modal 组件添加到 RootPanel :

public AddClassDialogViewImpl() {

  initWidget(uiBinder.createAndBindUi(this));

  cancel.addClickHandler(new ClickHandler() {
    @Override
    public void onClick(ClickEvent event) {
    //hide the widget
    addClassModal.hide();

    // unless you want to keep this modal as a singleton, you need to remove it from the DOM
    RootPanel.get().remove(AddClassDialogViewImpl.this);
    }
  });

  //add the widget to the DOM
  RootPanel.get().add(this);
  // show the widget
  addClassModal.show();

}
于 2013-09-06T06:23:54.057 回答