Hi
I am trying to generate some records when the user is hitting a button in the screen. It is creating and showing the records in the table. However, I need to set the data from the screen (header) for the detail (collection datasource). Not sure how can I!
I am appending below my controller code. the question is, how to get the value of TextField finaYear in the screen while i need it in the controller, see the ??? below:
public class FinancialYearEdit extends AbstractEditor<FinancialYear> {
@Inject
private CollectionDatasource<FinancialPeriod, UUID> financialPeriodDs;
@Inject
protected TextField finaYear;
@Inject
private Metadata metadata;
public void onSave() {
if (validateAll()) {
getDsContext().commit();
showNotification(getMessage("changesSaved"), NotificationType.HUMANIZED);
}
}
@Override
public boolean validateAll() {
for (FinancialPeriod task : financialPeriodDs.getItems()) {
if (task.getPeriod() == null ) {
showNotification(getMessage("fillRequiredFields"), NotificationType.TRAY);
return false;
}
}
return super.validateAll();
}
public void onLoad(Component source) {
Calendar gc1 = Calendar.getInstance();
Date date = new Date();
gc1.setTime(date);
gc1.set(Calendar.YEAR, 2016);
gc1.set(Calendar.MONTH, 0);
gc1.set(Calendar.DAY_OF_MONTH, 1);
long p=0;
//remove existing items from data source
//populate periods
for (long i=0;i<12;i++){
FinancialPeriod pd = metadata.create(FinancialPeriod.class);
//long month = gc1.get(Calendar.MONTH);
//p=month+1;
pd.setPeriod((long)gc1.get(Calendar.MONTH)+1);
gc1.set(Calendar.DAY_OF_MONTH, gc1.getActualMinimum(Calendar.DAY_OF_MONTH));
pd.setDateFrom(gc1.getTime());
gc1.set(Calendar.DAY_OF_MONTH, gc1.getActualMaximum(Calendar.DAY_OF_MONTH));
pd.setDateTo(gc1.getTime());
pd.setPeriodOpen(true);
pd.setFinancialYear(????);
financialPeriodDs.addItem(pd);
gc1.add(Calendar.MONTH, 1);
}
//order by Period
}
}