setting value to collection datasource from component

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


    }
}
finaYear.getValue()

If the TextField is associated with an entity attribute through a datasource, or if a datatype is assigned in the XML descriptor, the field will return a value of the specific type (e.g. Integer). Otherwise it returns String.

Hi
Thanks. I tried but no value is saved in the field FinaYear. No error found though. Any clue?

Set breakpoint to the

pd.setFinancialYear(finaYear.getValue())

line and ensure the field returns a value.

Hi
I did and found it is returning null value and when I run the program, getting null pointer exception


financialPeriodDs = {CollectionPropertyDatasourceImpl@11397} "financialPeriodDs{modified=false, parent=null}"
finaYear = null

What could be the reason why the finaYear is returning null value. I have entered value at the component level on the screen representing finaYear.