For looping through child entity to set edit-ability of screen components

Hey all,

I am trying to perform a for loop on a collection datacontainer to determine if some of the screen components in the parent edit-screen should be editable or not based on the status of this datacontainer collection.

These rows in the datacontainer have a enumeration named status. If one of the rows contains a status of “Nieuw”, “AfgekeurdWVB” or “AfgekeurdKLOK” then the fields of the parent entity should be editable. If this is not the case and all of the rows have a different status then the parent entity fields should be non editable.

My problem: I have succesfully performed a for loop with if statement in the same screen to determine if a status should be set or not the the row. But when trying to use the same loop to determine if the fields should be editable it does not work. The onInit is called succesfully since the collectionchangelisteners work.

Can anyone tell me why the first loop does not work at all, it does not set the value when the if statement is true, but in the second section of code the loop does work?

Keep in mind that I want to make the field editable as soon as one of the rows has a matching status. Thats why I chose to set the editability to false at first, and then change it if it is true.

The code with the loop that does not work:

public void onInit(InitEvent event) {

    //Voeg listeners toe aan het scherm
    urenRegelsDc.addCollectionChangeListener(event1 -> urenbriefDc.getItem().setUrenTotaal(calculateUrenTotaal()));
    urenRegelsDc.addCollectionChangeListener(event2 -> urenbriefDc.getItem().setOverurenTotaal(calculateOverurenTotaal()));
    urenRegelsDc.addCollectionChangeListener(event3 -> urenbriefDc.getItem().setTvtTotaal(calculateTvtTotaal()));
    urenTvt.addTextChangeListener(textChangeEvent -> urenbriefDc.getItem().setTvtTotaal(calculateTvtTotaal()));

    //Determine if screen should be editable or not.

    //If any of the rows match the status, make the field editable
    for (UrenRegels urenRegels : urenRegelsDc.getItems()) {
        if (urenRegels.getUrenRegelStatus() == Status.NIEUW | urenRegels.getUrenRegelStatus() == Status.AFGEKEURDWVB | urenRegels.getUrenRegelStatus() == Status.AFGEKEURDKLOK) {

And this is the code where I use the same for loop to loop through the same rows to change the status, and for some reason this does seem to work.

public void onIndienButtonClick() {
        //Doorloop alle urenregels, indien de status Nieuw, of afgekeurd is, lever de regel dan in. Indien dit niet zo is, doe niks.
        for (UrenRegels urenRegels : urenRegelsDc.getItems()) {
            if (urenRegels.getUrenRegelStatus() == Status.NIEUW | urenRegels.getUrenRegelStatus() == Status.AFGEKEURDWVB | urenRegels.getUrenRegelStatus() == Status.AFGEKEURDKLOK) {

        //Verander de status van alle materiaalregels die nog op nieuw staan (deze hebben geen verdere afhandeling nodig omdat de WVB deze zelf goedkeurt of verwijderd, geen terugkoppeling nodig)
        for (MateriaalRegels materiaalRegels : materiaalRegelsDc.getItems()) {
            if (materiaalRegels.getMateriaalRegelStatus() == Status.NIEUW) {

        //Set urenbrief op ingeleverd
        Urenbrief urenbrief = urenbriefDc.getItem();

        // Commit en sluit het scherm (zodat de lock van toepassing wordt)

Your first example doesn’t seem to changing items that are in the container, but your second example does.

So at a guess, I think you need to use


in the second example.

In onInit(InitEvent event) method your urenRegelsDc just doesn’t contain any items. Data is loaded right before showing the screen (if you use @LoadDataBeforeShow), so you should move your loop in an AfterShowEvent handler.

1 Like

Works like a charm, thank you once again! I didn’t think of when the actual data in the table was loaded.