I have problems with binding value in DateField. In ScheduleWindow i added DateField and bind it with value from Schedule class and i can’t edit this value directly from window. I think that DateField in readOnly mode, but why ?
[code]
public class ScheduleWindow extends Window {
public static final String ID = "schedulewindow";
private final BeanFieldGroup<Schedule> fieldGroup;
private WindowMode mode;
private Button saveButton;
@PropertyId("start")
private DateField startDate;
@PropertyId("end")
private DateField endDate;
public ScheduleWindow(Schedule schedule, WindowMode mode) {
DashboardUI.getGlobalEventBus().register(this);
this.mode = mode;
addStyleName("profile-window");
setId(ID);
Responsive.makeResponsive(this);
setModal(true);
addCloseShortcut(KeyCode.ESCAPE, null);
setResizable(false);
setClosable(true);
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);
content.addComponent(buildFooter());
detailsWrapper.addComponent(buildWindowContent());
fieldGroup = new BeanFieldGroup<Schedule>(Schedule.class);
fieldGroup.setItemDataSource(schedule);
fieldGroup.bindMemberFields(this);
}
private Component buildWindowContent() {
HorizontalLayout root = new HorizontalLayout();
if (mode == WindowMode.ADD) {
root.setCaption("Добавление");
} else if (mode == WindowMode.EDIT) {
root.setCaption("Редактирование");
}
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);
Label lblHeader = new Label("Введите данные");
lblHeader.addStyleName(ValoTheme.LABEL_H4);
lblHeader.addStyleName(ValoTheme.LABEL_COLORED);
details.addComponent(lblHeader);
startDate = new DateField("Начало");
startDate.setReadOnly(false);
startDate.setLocale(Locale.getDefault());
startDate.setResolution(Resolution.MINUTE);
startDate.setEnabled(true);
startDate.setRequired(true);
details.addComponent(startDate);
endDate = new DateField("Конец");
endDate.setResolution(Resolution.MINUTE);
details.addComponent(endDate);
return root;
}
private Component buildFooter() {
HorizontalLayout footer = new HorizontalLayout();
footer.addStyleName(ValoTheme.WINDOW_BOTTOM_TOOLBAR);
footer.setWidth(100.0f, Unit.PERCENTAGE);
if (mode == WindowMode.ADD) {
saveButton = new Button("Добавить запись");
} else if (mode == WindowMode.EDIT) {
saveButton = new Button("Отредактировать запись");
}
saveButton.addStyleName(ValoTheme.BUTTON_PRIMARY);
saveButton.addClickListener(new ClickListener() {
@Override
public void buttonClick(ClickEvent event) {
try {
if (fieldGroup.isValid()) {
fieldGroup.commit();
DashboardUI.getDataProvider().saveSchedule(fieldGroup.getItemDataSource().getBean());
Notification success = null;
if (mode == WindowMode.ADD) {
success = new Notification("Запись добавлена!");
} else if (mode == WindowMode.EDIT) {
success = new Notification("Запись отредактирована!");
}
success.setDelayMsec(2000);
success.setStyleName("bar success small");
success.setPosition(Position.BOTTOM_CENTER);
success.show(Page.getCurrent());
DashboardUI.getGlobalEventBus()
.post(new SchedueltDataUpdatedEvent());
close();
} else {
Notification.show("Введите все необходимые данные!", Type.WARNING_MESSAGE);
}
} catch (CommitException e) {
Notification.show("Ошибка при добавлении записи!", Type.ERROR_MESSAGE);
}
}
});
saveButton.focus();
footer.addComponent(saveButton);
footer.setComponentAlignment(saveButton, Alignment.TOP_RIGHT);
return footer;
}
@Override
public void close() {
DashboardUI.getGlobalEventBus().unregister(this);
super.close();
}
}
[/code]