从Vaadin中的对话框中获取数据对象



我为我的Vaadin应用程序编写了一个扩展Dialog的类。对话框面板包含几个文本字段、配对日期选择器等。此对话框的目的是构建Filter类的实例。这是一段代码。全班同学太大了,不能在这里展示。

public class FilterPanel extends Dialog {
private Filter filter;
private TextField nameField;
private TextField countryField;
private DatePicker postingDateField;
private TextField fromYear;
private TextField toYear;
private ComboBox tagField;
public FilterPanel() {
buildDialog();
}
public FilterPanel(Filter filter) {
this.filter = filter;
}

这一切都运行良好,并且正在正确地构建对象。我的问题是,在关闭对话框后,我无法将此对象从对话框中取出。我通过调用close((函数来显式关闭它。我放置了Dialog。DialogCloseActionEvent侦听器插入到调用类中,但它没有被调用。

@Override
protected void onAttach(AttachEvent attachEvent) {
super.onAttach(attachEvent); 
registration = ComponentUtil.addListener(attachEvent.getUI(), DialogCloseActionEvent.class,
event -> {
Dialog source = event.getSource();
if(source instanceof FilterPanel) {
reader = ((FilterPanel)source).getFilter();
}
});
}

我从按钮点击监听器打开这个对话框,并在显示对话框后尝试调用getFilter((方法。

this.filterButton.addClickListener((ClickEvent<Button> clickEvent) -> {
FilterPanel fp = config.getFilterPanel(filter);
fp.open();
filter = fp.getFilter();
});

但是它总是返回null。我在调试器的这一行放置了一个断点,在对话框打开之前调用它。根据文档,Dialog默认情况下被认为是模态的。我该如何让它发挥作用?请帮帮我。

我确实尝试过使用Dialog。OpenedChangedEvent,但它没有按我的需要工作。While Dialog。DialogCloseActionEvent根本没有启动。确实启动了,但时机不对。最终,我编写了自己的ComponentEvent扩展,并在需要时明确地启动它

最新更新