Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/gwt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
GWT-整个表格中按钮ClickEvent后的单元格值相同_Gwt - Fatal编程技术网

GWT-整个表格中按钮ClickEvent后的单元格值相同

GWT-整个表格中按钮ClickEvent后的单元格值相同,gwt,Gwt,我的GWT项目是一个简单的日历。您可以通过单击表格单元格添加日期,该单元格将打开一个对话框以输入名称和说明。 当您单击“确定”或用“Abbrechen”取消时,日期将写入tablecell。 我的代码(在Eclipse中构建): 为什么??或者,是否有更好的可能性“管理”代码?您需要为单击处理程序使用HandlerRegistration。由于您没有清除click处理程序,因此它也会调用早期事件 有关详细信息,请参阅以下链接: 看来你对GWT还很陌生。以下是工作解决方案: 包com.my.f

我的GWT项目是一个简单的日历。您可以通过单击表格单元格添加日期,该单元格将打开一个对话框以输入名称和说明。 当您单击“确定”或用“Abbrechen”取消时,日期将写入tablecell。 我的代码(在Eclipse中构建):


为什么??或者,是否有更好的可能性“管理”代码?

您需要为单击处理程序使用HandlerRegistration。由于您没有清除click处理程序,因此它也会调用早期事件

有关详细信息,请参阅以下链接:

看来你对GWT还很陌生。以下是工作解决方案:

包com.my.first.client

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.shared.HandlerRegistration;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.DecoratorPanel;
import com.google.gwt.user.client.ui.DialogBox;
import com.google.gwt.user.client.ui.Grid;
import com.google.gwt.user.client.ui.HTMLTable;
import com.google.gwt.user.client.ui.HTMLTable.Cell;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.TextBox;

/**
 * Entry point classes define <code>onModuleLoad()</code>.
 */
public class ShowCase implements EntryPoint {
    int a = 24; // Anzahl Zeit-Zeilen (Normalfall 24 -> 0:00 - 23:00)
    int start = 7;
    int end = 21;

    DecoratorPanel panel = new DecoratorPanel();

    Grid t = new Grid((a + 1), 8); //

    String days[] = { " ", "Montag", "Dienstag", "Mittwoch", "Donnerstag", "Freitag", "Samstag", "Sonntag" };

    String data = null, str1 = null, str2 = null;

    DialogBox dialog = new DialogBox();
    Grid dialoggrid = new Grid(3, 2); // Grid-Layout für gesamte DialogBox
    Label lname = new Label("Name");
    Label lbeschr = new Label("Beschreibung");
    TextBox tbname = new TextBox();
    TextBox tbbeschr = new TextBox();
    Button ok = new Button("OK");
    Button cancel = new Button("Abbrechen");

    HandlerRegistration okHandlerRegistration;

    int indexrow, indexcol;

    DialogBox leer = new DialogBox();
    Button okleer = new Button("OK");

    public void onModuleLoad() {
        t.setBorderWidth(1);
        t.setCellSpacing(0);
        for (int row = 0; row < (a + 1); row++) {
            for (int col = 0; col < 8; col++) {
                if (col == 0) {
                    int z = row - 1;
                    System.out.println("Spalte 0 Zeit setzen: " + row);
                    t.setText(row, col, z + ":00"); // Spalte 0 Zeit setzen
                } else {
                    t.setText(row, col, "");
                }

                t.setText(0, col, days[col]); // Tage aus days in Zeile 0 setzen
                t.getCellFormatter().setWidth(row, 0, "50px");
                t.getCellFormatter().setWidth(row, col, "150px");
            }
        } // end for(int row=0...)

        panel.add(t);
        RootPanel.get("content").add(panel);

        t.addClickHandler(new ClickHandler() {
            public void onClick(ClickEvent event) {

                System.out.println("Neuer Klick!");
                Cell cell = ((HTMLTable) event.getSource()).getCellForEvent(event);
                System.out.println("Cell cell HTML Table");

                /*
                 * if (data.equals("1")){ tbname.setText(text);
                 * tbbeschr.setText(null); }
                 */

                System.out.println("data1: " + data);
                // Uhrzeit-Spalte und Wochentagsreihe absichern
                if (!(cell.getRowIndex() == 0) && !(cell.getCellIndex() == 0)) {
                    System.out.println("Get Index(): " + cell.getRowIndex() + "," + cell.getCellIndex()); // Ausgabe
                                                                                                            // von
                                                                                                            // Reihe
                                                                                                            // und
                                                                                                            // Spalte
                    final int indexrow = cell.getRowIndex();
                    final int indexcol = cell.getCellIndex();

                    // Dialog belegen und anzeigen
                    dialoggrid.setCellSpacing(0);
                    dialoggrid.setCellPadding(0);

                    tbname.setText(null);
                    tbbeschr.setText(null);

                    System.out.println("TBName: " + tbname.getText());
                    System.out.println("TBBeschr: " + tbbeschr.getText());

                    dialoggrid.setWidget(0, 0, lname);
                    dialoggrid.setWidget(1, 0, lbeschr);
                    dialoggrid.setWidget(2, 0, ok);

                    dialoggrid.setWidget(0, 1, tbname);
                    dialoggrid.setWidget(1, 1, tbbeschr);
                    dialoggrid.setWidget(2, 1, cancel);

                    dialog.setWidget(dialoggrid);
                    dialog.center();
                    dialog.setModal(false);

                    if (tbname.getText().equals(null)) {
                        System.out.println("if tbname.getText equals null");
                    }

                    System.out.println("Dialog show");
                    dialog.show();

                    if (okHandlerRegistration != null) {
                        okHandlerRegistration.removeHandler();
                    }

                    okHandlerRegistration = ok.addClickHandler(new ClickHandler() {
                        public void onClick(ClickEvent event) {
                            System.out.println("ok Click");
                            // Überprüfen ob TextBox Name und Beschreibung nicht
                            // leer sind
                            if ((!tbname.getText().equals(null)) && (!tbbeschr.getText().equals(null))) {
                                System.out.println("Wenn tbname & tbbeschr nicht leer sind");
                                str1 = tbname.getText();
                                str2 = tbbeschr.getText();
                                data = str1 + ", " + str2;
                                t.setText(indexrow, indexcol, data);
                                dialog.hide();
                                System.out.println("#1: " + data + "#");
                                data = null;
                                System.out.println("#2: " + data + "#");
                            } else {
                                System.out.println("leer!");
                                leer.setText("Felder duerfen nicht leer sein!");
                                leer.add(okleer);
                                leer.center();
                                leer.setModal(true);
                                leer.show();

                                okleer.addClickHandler(new ClickHandler() {
                                    public void onClick(ClickEvent event) {
                                        System.out.println("okleer click");
                                        leer.hide();
                                    }
                                });
                            } // end else

                        }
                    }); // end ok.addClickHandler

                    cancel.addClickHandler(new ClickHandler() {
                        public void onClick(ClickEvent event) {
                            System.out.println("cancel Click");
                            dialog.hide();
                            tbname.setText(null);
                            tbbeschr.setText(null);
                        }
                    }); // end cancel.addClickHandler

                } // end if(!(cellindex) && !(rowindex) =0 )

            } // end public void OnClick()
        }); // end t.addClickHandler
    } // end onModuleLoad(}

}

对不起,我忘了我的帖子祝你圣诞快乐。谢谢,现在它工作正常了。我试了一下,就像你做的一样(sry,忘了告诉我,我做了什么),但它错了(run只有一次)。是的,我对GWT很陌生。另一个问题:哪个数据库是保存和加载值的好方法?谢谢你的帮助,祝你新年快乐。:)编辑:但现在的问题是,else(当所有文本框都为空时显示一个对话框)不能正常工作。它是从if之前的框中获取值。。。
Neuer Klick!
Cell cell HTML Table
data1: null
Get Index(): 1,1
TBName: 
TBBeschr: 
Dialog show
ok Click
Wenn tbname & tbbeschr nicht leer sind
#1: rt, qw#
#2: null#
Neuer Klick!
Cell cell HTML Table
data1: null
Get Index(): 1,2
TBName: 
TBBeschr: 
Dialog show
ok Click
Wenn tbname & tbbeschr nicht leer sind
#1: gh, tz#
#2: null#
ok Click
Wenn tbname & tbbeschr nicht leer sind
#1: gh, tz#
#2: null#
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.shared.HandlerRegistration;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.DecoratorPanel;
import com.google.gwt.user.client.ui.DialogBox;
import com.google.gwt.user.client.ui.Grid;
import com.google.gwt.user.client.ui.HTMLTable;
import com.google.gwt.user.client.ui.HTMLTable.Cell;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.TextBox;

/**
 * Entry point classes define <code>onModuleLoad()</code>.
 */
public class ShowCase implements EntryPoint {
    int a = 24; // Anzahl Zeit-Zeilen (Normalfall 24 -> 0:00 - 23:00)
    int start = 7;
    int end = 21;

    DecoratorPanel panel = new DecoratorPanel();

    Grid t = new Grid((a + 1), 8); //

    String days[] = { " ", "Montag", "Dienstag", "Mittwoch", "Donnerstag", "Freitag", "Samstag", "Sonntag" };

    String data = null, str1 = null, str2 = null;

    DialogBox dialog = new DialogBox();
    Grid dialoggrid = new Grid(3, 2); // Grid-Layout für gesamte DialogBox
    Label lname = new Label("Name");
    Label lbeschr = new Label("Beschreibung");
    TextBox tbname = new TextBox();
    TextBox tbbeschr = new TextBox();
    Button ok = new Button("OK");
    Button cancel = new Button("Abbrechen");

    HandlerRegistration okHandlerRegistration;

    int indexrow, indexcol;

    DialogBox leer = new DialogBox();
    Button okleer = new Button("OK");

    public void onModuleLoad() {
        t.setBorderWidth(1);
        t.setCellSpacing(0);
        for (int row = 0; row < (a + 1); row++) {
            for (int col = 0; col < 8; col++) {
                if (col == 0) {
                    int z = row - 1;
                    System.out.println("Spalte 0 Zeit setzen: " + row);
                    t.setText(row, col, z + ":00"); // Spalte 0 Zeit setzen
                } else {
                    t.setText(row, col, "");
                }

                t.setText(0, col, days[col]); // Tage aus days in Zeile 0 setzen
                t.getCellFormatter().setWidth(row, 0, "50px");
                t.getCellFormatter().setWidth(row, col, "150px");
            }
        } // end for(int row=0...)

        panel.add(t);
        RootPanel.get("content").add(panel);

        t.addClickHandler(new ClickHandler() {
            public void onClick(ClickEvent event) {

                System.out.println("Neuer Klick!");
                Cell cell = ((HTMLTable) event.getSource()).getCellForEvent(event);
                System.out.println("Cell cell HTML Table");

                /*
                 * if (data.equals("1")){ tbname.setText(text);
                 * tbbeschr.setText(null); }
                 */

                System.out.println("data1: " + data);
                // Uhrzeit-Spalte und Wochentagsreihe absichern
                if (!(cell.getRowIndex() == 0) && !(cell.getCellIndex() == 0)) {
                    System.out.println("Get Index(): " + cell.getRowIndex() + "," + cell.getCellIndex()); // Ausgabe
                                                                                                            // von
                                                                                                            // Reihe
                                                                                                            // und
                                                                                                            // Spalte
                    final int indexrow = cell.getRowIndex();
                    final int indexcol = cell.getCellIndex();

                    // Dialog belegen und anzeigen
                    dialoggrid.setCellSpacing(0);
                    dialoggrid.setCellPadding(0);

                    tbname.setText(null);
                    tbbeschr.setText(null);

                    System.out.println("TBName: " + tbname.getText());
                    System.out.println("TBBeschr: " + tbbeschr.getText());

                    dialoggrid.setWidget(0, 0, lname);
                    dialoggrid.setWidget(1, 0, lbeschr);
                    dialoggrid.setWidget(2, 0, ok);

                    dialoggrid.setWidget(0, 1, tbname);
                    dialoggrid.setWidget(1, 1, tbbeschr);
                    dialoggrid.setWidget(2, 1, cancel);

                    dialog.setWidget(dialoggrid);
                    dialog.center();
                    dialog.setModal(false);

                    if (tbname.getText().equals(null)) {
                        System.out.println("if tbname.getText equals null");
                    }

                    System.out.println("Dialog show");
                    dialog.show();

                    if (okHandlerRegistration != null) {
                        okHandlerRegistration.removeHandler();
                    }

                    okHandlerRegistration = ok.addClickHandler(new ClickHandler() {
                        public void onClick(ClickEvent event) {
                            System.out.println("ok Click");
                            // Überprüfen ob TextBox Name und Beschreibung nicht
                            // leer sind
                            if ((!tbname.getText().equals(null)) && (!tbbeschr.getText().equals(null))) {
                                System.out.println("Wenn tbname & tbbeschr nicht leer sind");
                                str1 = tbname.getText();
                                str2 = tbbeschr.getText();
                                data = str1 + ", " + str2;
                                t.setText(indexrow, indexcol, data);
                                dialog.hide();
                                System.out.println("#1: " + data + "#");
                                data = null;
                                System.out.println("#2: " + data + "#");
                            } else {
                                System.out.println("leer!");
                                leer.setText("Felder duerfen nicht leer sein!");
                                leer.add(okleer);
                                leer.center();
                                leer.setModal(true);
                                leer.show();

                                okleer.addClickHandler(new ClickHandler() {
                                    public void onClick(ClickEvent event) {
                                        System.out.println("okleer click");
                                        leer.hide();
                                    }
                                });
                            } // end else

                        }
                    }); // end ok.addClickHandler

                    cancel.addClickHandler(new ClickHandler() {
                        public void onClick(ClickEvent event) {
                            System.out.println("cancel Click");
                            dialog.hide();
                            tbname.setText(null);
                            tbbeschr.setText(null);
                        }
                    }); // end cancel.addClickHandler

                } // end if(!(cellindex) && !(rowindex) =0 )

            } // end public void OnClick()
        }); // end t.addClickHandler
    } // end onModuleLoad(}

}