Hi,
I have the following code adapted from dashboard demo. I changed some parts of it; mainly events part. Following code is a sub window that is added to the main window. The problem is; we can not close the sub window. I am skipping some parts of the code for better readability.
In the buildFooter() method, notification is presented to the user but right after it the close() method call doesnt perform anything. In addition Close Shortcut doesnt work and with setCloseable(true) property the window can not be closed from the upper-right X sign.
Any help would be much appreciated.
Thanks
package xxx.ui;
@SuppressWarnings("serial")
@SessionScoped
public class UserSettingsWindow extends Window {
public static final String ID = "userSettingsWindow";
private BeanFieldGroup<User> fieldGroup;
private ResourceBundle res;
@EJB
UserService userService;
@PropertyId("firstName")
private TextField firstNameField;
@PropertyId("lastName")
private TextField lastNameField;
@PropertyId("email")
private TextField emailField;
@PropertyId("password")
private TextField passwordField;
public UserSettingsWindow() {
super();
}
public void init(User user) {
res = ((PohatsUI)UI.getCurrent()).getResourceBundle();
addStyleName("profile-window");
setId(ID);
Responsive.makeResponsive(this);
setModal(true);
addCloseShortcut(KeyCode.ESCAPE, null);
setResizable(false);
setClosable(false);
setHeight(90.0f, Unit.PERCENTAGE);
VerticalLayout content = new VerticalLayout();
content.setSizeFull();
content.setMargin(new MarginInfo(true, false, false, false));
setContent(content);
TabSheet detailsWrapper = new TabSheet();
detailsWrapper.setSizeFull();
detailsWrapper.addStyleName(ValoTheme.TABSHEET_PADDED_TABBAR);
detailsWrapper.addStyleName(ValoTheme.TABSHEET_ICONS_ON_TOP);
detailsWrapper.addStyleName(ValoTheme.TABSHEET_CENTERED_TABS);
content.addComponent(detailsWrapper);
content.setExpandRatio(detailsWrapper, 1f);
detailsWrapper.addComponent(buildProfileTab());
content.addComponent(buildFooter());
fieldGroup = new BeanFieldGroup<>(User.class);
fieldGroup.bindMemberFields(this);
fieldGroup.setItemDataSource(user);
}
private Component buildProfileTab() {
HorizontalLayout root = new HorizontalLayout();
root.setCaption(res.getString("UserSettingsWindow_profileCB"));
root.setIcon(FontAwesome.USER);
root.setWidth(100.0f, Unit.PERCENTAGE);
root.setSpacing(true);
root.setMargin(true);
root.addStyleName("profile-form");
FormLayout details = new FormLayout();
details.addStyleName(ValoTheme.FORMLAYOUT_LIGHT);
root.addComponent(details);
root.setExpandRatio(details, 1);
firstNameField = new TextField(res.getString("UserSettingsWindow_firstnameLB"));
details.addComponent(firstNameField);
lastNameField = new TextField(res.getString("UserSettingsWindow_lastnameLB"));
details.addComponent(lastNameField);
passwordField = new TextField(res.getString("UserSettingsWindow_passwordLB"));
details.addComponent(passwordField);
Label section = new Label(res.getString("UserSettingsWindow_contactInfoLB"));
section.addStyleName(ValoTheme.LABEL_H4);
section.addStyleName(ValoTheme.LABEL_COLORED);
details.addComponent(section);
emailField = new TextField(res.getString("UserSettingsWindow_emailLB"));
emailField.setWidth("100%");
emailField.setRequired(true);
emailField.setNullRepresentation("");
details.addComponent(emailField);
return root;
}
private Component buildFooter() {
HorizontalLayout footer = new HorizontalLayout();
footer.addStyleName(ValoTheme.WINDOW_BOTTOM_TOOLBAR);
footer.setWidth(100.0f, Unit.PERCENTAGE);
Button ok = new Button(res.getString("UserSettingsWindow_okBT"));
ok.addStyleName(ValoTheme.BUTTON_PRIMARY);
ok.addClickListener(new ClickListener() {
@Override
public void buttonClick(ClickEvent event) {
try {
fieldGroup.commit();
userService.updateUserSettings(fieldGroup.getItemDataSource().getBean());
Notification success = new Notification(res.getString("UserSettingsWindow_settingsUpdateSuccessLB"));
success.setDelayMsec(2000);
success.setStyleName("bar success small");
success.setPosition(Position.BOTTOM_CENTER);
success.show(Page.getCurrent());
close();
} catch (CommitException e) {
Notification.show("Error while updating profile", Type.ERROR_MESSAGE);
}
}
});
ok.focus();
footer.addComponent(ok);
footer.setComponentAlignment(ok, Alignment.TOP_RIGHT);
return footer;
}
}