Change Nested Collection Datasource via generated Column of Table

Hello together,

I have two Entitys with a “MANY_TO_MANY” relationship and I want to Add and Remove Items to one of the entitys, via “ticking” a Checkbox (generated Columnd of a Table):
image

The Table has a CollectionDatasource of the “opposite Entity” which contains all of the Items the user might want to add (or remove).

Please have a look at the following code of mine:

@Override
protected void postInit() {
	super.postInit();
	listeGebiete = auftragnehmerDs.getItem().getAnPlzGebietFK();
	}

    public Component generateGebietZugewiesenCell(GlobalPlzGebiet entity) {
    	CheckBox cbox =  (CheckBox) componentsFactory.createComponent(CheckBox.NAME);
    	if(listeGebiete != null) {
	    	for (GlobalPlzGebiet gebiet : listeGebiete) {
	    		if(gebiet.getId().equals(entity.getId())) {cbox.setValue(true); break;}
	    	}
    	}
    	cbox.addValueChangeListener(evt -> changePlzGebiet(evt));
    	return cbox;
    }


	private void changePlzGebiet(ValueChangeEvent evt) {
		if ((boolean) evt.getValue()) {
			auftragnehmerDs.getItem().getAnPlzGebietFK().add(globalPlzGebietsDs.getItem());
			//auftragnehmerDs.commit();
		}
		else {
			auftragnehmerDs.getItem().getAnPlzGebietFK().remove(globalPlzGebietsDs.getItem());
			//auftragnehmerDs.commit();
			
		}
	}

This works “kinda fine”, as long as i call the Datasource commit after adding or removing the Item. But i assume thats not the way, it was designed… for example there is no longer any need for the “ok” , “Cancel” Button of the Edit Screen.

Without calling the commit, no changes get saved to the Database. Also when pressing Cancel, There is no message “you have unsaved changes”, which usually appears when i change something.

Can you please tell me what am i doing wrong ? i tried calling isModified but that doens’t change anything.

Thanks and best Regards
Daniel

Hello, @dannywall55s

It seems that your problem should fixed here in 6.9 version. YouTrack ticket: link.

Could you check how it works in 6.9-SNAPSHOT version?

Regards,
Daniil.

Hello Daniil,

Thanks for the Info. I got it Working by creating a nested datasource for the collection. I injected the nested datasource and used the additem und removeitem function, because These change the datasource status to modified… This way its Working fine as expected…

Thanks anyway
Daniel

Oh, I thought that you had already used nested datasource.

You’re welcome!