How to Select data from multiple tables based on user preference

  • I would like to select data from 2 different source tables which have same set of columns.
  • for each column user specify order of preference table1 or table2. e.g if colum1 value is present in table1 show that else use value from table2
  • When user searches for text in key field of 2 tables and display column values based on order of preference.

Could anyone help me how to achieve this?

As I mentioned, you can find examples of using non-persistent entities in Timesheets sample application.
Look at fillExistingTimeEntries() method of the ApproveScreen class. It fills up the datasource with instances of non-persistent WeeklyReportEntry entity.

The first thought which came to my mind is to create a database view with “select … union …” and map it to an entity. Then use standard platform facilities to show the entity in UI. Probably this is too rigid and doesn’t solve your problem.

More flexible way would be to create two identical persistent entities and map them to your tables. Then create a non-persistent entity with the same set of attributes.
In your screen, define a datasource for the non-persistent entity and set refreshMode=“NEVER” for it (see for example approve-screen.xml in Timesheets sample application). In the screen controller, fill up the datasource using its addItem() or includeItem() methods. The non-persistent entity instances can be created either right in the screen, or in a middleware service. In the former case, you can use standard datasources for your persistent entities to load.

I created 2 persistent entity and one non persistent entity. then created a screen"Master data" that extends LookupWindow and added datasource for non-persistent entiry. But I don’t see link to new screen in main application. where do we link new screen?

please ignore. I am able to show new screen under application Menu.

Could you give me some example of controller loading non-persistance entity?

You can also control your menu from CUBA studio by selecting OTHER -> Web Client Menu -> Edit