Hi,
I’m trying to get an editable table that contains a tokenlist (to be set per row). However, I’m unable to specify the datasource for the tokenlist appropriately such that it operates on the actual row content rather than some superset (as it appears to work now).
The table data refers to a list of authorisations related to a single information system and is included on the edit screen of the information system.
Relevant screen XML:
....
<datasource id="informationSystemDs"
class="com.axxemble.base27.entity.InformationSystem"
view="informationSystem-view">
<collectionDatasource id="sysAuthorisationsDs"
property="authorisations">
<collectionDatasource id="sysAuthGroups" property="groups"/>
<collectionDatasource id="sysAuthUsers" property="users"/>
</collectionDatasource>
</datasource>
....
<table id="sysAuthorisationsTable"
editable="true"
width="100%">
<actions>
<action id="add" invoke="addAuthorisation"/>
<action id="remove" invoke="removeAuthorisation" trackSelection="true"/>
</actions>
<columns>
<column id="name" editable="true"/>
<column id="description" editable="true"/>
<column id="groups" caption="msg://com.axxemble.base27.entity/Authorisation.groups" editable="true"/>
<column id="users" caption="msg://com.axxemble.base27.entity/Authorisation.users" editable="true"/>
</columns>
<rows datasource="sysAuthorisationsDs"/>
<rowsCount/>
<buttonsPanel>
<button icon="font-icon:PLUS" action="sysAuthorisationsTable.add" caption=""/>
<button action="sysAuthorisationsTable.remove"
caption="msg://Remove"/>
</buttonsPanel>
</table>
Relevan controller code:
....
@Inject
private Table<Authorisation> sysAuthorisationsTable;
@Inject
private CollectionDatasource<Authorisation, UUID> sysAuthorisationsDs;
@Inject
private Metadata metadata;
@Inject
private CollectionDatasource<Group, UUID> groupsDs;
@Inject
private CollectionDatasource<Staff, UUID> staffsDs;
@Inject
private CollectionDatasource<Group, UUID> sysAuthGroups;
@Inject
private CollectionDatasource<Staff, UUID> sysAuthUsers;
@Inject
private ComponentsFactory componentsFactory;
@Override
public void init(Map<String, Object> params) {
// Set controls for authorisation table
sysAuthorisationsTable.addGeneratedColumn("groups", p -> {
TokenList group = componentsFactory.createComponent(TokenList.class);
group.setDatasource(sysAuthGroups);
group.setOptionsDatasource(groupsDs);
group.setInline(true);
group.setClearButtonCaption("");
group.setClearButtonIcon("font-icon:CLOSE");
return group;
});
sysAuthorisationsTable.addGeneratedColumn("users", p -> {
TokenList user = componentsFactory.createComponent(TokenList.class);
user.setDatasource(sysAuthUsers);
user.setOptionsDatasource(staffsDs);
user.setInline(true);
user.setClearButtonCaption("");
user.setClearButtonIcon("font-icon:CLOSE");
return user;
});
}
.....
// General save/cancel buttons for the information system
public void onBtnSaveClick() {
saveAuthorisations();
super.commitAndClose();
}
public void onBtnCancelClick() {
close(CLOSE_ACTION_ID);
}
// Actions for the authorisations
public void addAuthorisation() {
Authorisation auth = metadata.create(Authorisation.class);
auth.setInfoSystem(getItem());
sysAuthorisationsDs.addItem(auth);
}
public void removeAuthorisation() {
if (sysAuthorisationsDs.getItem() != null) {
sysAuthorisationsDs.removeItem(sysAuthorisationsDs.getItem());
}
}
private void saveAuthorisations() {
if (validateAll()) {
sysAuthorisationsDs.commit();
//showNotification(getMessage("changesSaved"), NotificationType.HUMANIZED);
}
}
@Override
public boolean validateAll() {
for (Authorisation auth : sysAuthorisationsDs.getItems()) {
if (StringUtils.isEmpty(auth.getName())) {
showNotification(getMessage("fillRequiredFields"), NotificationType.TRAY);
return false;
}
}
return super.validateAll();
}
When running the application, all works well but the values on the tokenlists are a superset of all selected items and are applied at each row in the table.
Any help appreciated.