Hierarchical datasources Cuba 7

Hi

I wanted to create an entity and screen for a hierarchical table with parent and child keys in one table.
I cannot find any How To for Cuba 7, just for Cuba 6.

Could you please provide me a documentation hot to work with that?

Thanks
Thomas

Hi,

In v7 instead of hierarchical datasource you can use CollectionContainer and in screen layout use <collection> element:

<data>
    <collection id="demoDc"
                class="com.company.demo.entity.Demo"
                view="demo-view">
        <loader id="demoLoader">
            <query>
                <![CDATA[select e from demo$Demo e]]>
            </query>
        </loader>
    </collection>
</data>

See TreeTable documentation and sample.

How to get the Child Items and Parent using Collection Container in the Controller…?

You need to get TreeTableItems from your TreeTable and then get children. For instance:

@Inject
private TreeTable<Task> treeTable;

@Subscribe
private void onInit(InitEvent event) {
    TreeTableItems<Task> treeTableItems = (TreeTableItems<Task>) treeTable.getItems();
    Collection<Task> children = (Collection<Task>) treeTableItems.getChildren(getSomeItem());
}

TreeTableItems is an interface for providing data for TreeTable. It contains methods for getting parent, childrens, etc.

Thanks for help

Can you also help me to get an running sql query based on the selected departments?
I have a browse screen with all departments. Then I can select a department and need to have a lookup field based on a sql query and the selected departments:

The followinf query:
Select e FROM l2s_Department e
WHERE e.dept_fk_dept IS NULL
AND e.dept_number <> :selecteddepartmentID
ORDER BY e.dept_number

I wanted to get the ID of the selected department in :departmentDC.

But got the error :slight_smile:IllegalStateException: Query argument departmentsDC not found in the list of parameters provided during query execution.

Hi!

This question is not related to the topic subject. Please create a new topic with detailed explanation.

Hi

I have created a new topic, but this question is also related to the tree view.
After creating the view with tree, I can select a row for editing.

Than I will update the selected item and set him a new parent from the same table. How can I avoid that the selected item is in the list of the parents that he can select?

When I set the same row as parent as I selected, the complete data row is removed from my view.

Thomas