Accessing Date attribute from another Entity

I have a ONE-TO-MANY composition relation between Transaction and Quote.

In transaction date filed I need to set the Quote date (field).

What code I have to put in Transaction controller?

public class TransactionEdit extends AbstractEditor<Transaction> {
     @Override
     protected void initNewItem(Transaction transaction) {
      //       transaction.setDate(new Date());
         transaction.setDate(transaction.getQuote().get().getDate());
     }
}    
error: method get in interface List <E> cannot be applied to given types;

Hi,

Please use ``` for code blocks (before and after).

First, use an IDE or CUBA Studio v.7+ to write code. It will give you more understanding about available methods and their parameters.

Second, when you create a new Transaction, what Quote must be used to get date from?

Hi Konstantin,

Quote are nested in Transaction.
The problem was solved with an (After) Entity Listener but only for (Edit) existed transactions (already present in database).
For new Transaction (Quote) - that is not present in database, I think I have to use CreateAction class and DataManager interface in Transaction Browse Controller.
Do you have an example in this respect?

Look here: D.Assigning Initial Values - CUBA Platform. Developer’s Manual

Hi Konstantin,
Thank you for your reply.

I think I have to use initNewItem (or postInit) method but I don’t know how.
What is difference between init and initNewItem? One is for Association and another one for Composition?

Apparently my case is like in init example.
The problem is that in Transaction-browse.xml I don’t have quoteDs datasource. Only in Transaction-edit.xml. But in TransactionEdit controller I dont’n have Transaction action. So I cannot use init with TransactionTableCreate…

On the other hand in initNewItem I cannot set Transaction only Quote.

init() is invoked every time the screen is shown.
initNewItem() is invoked for editor screens when it is shown for a new entity instance. You can set attributes of the new entity in this method before showing it to the user.

In the new screen API, instead of the init() method subscribe to InitEvent and instead of initNewItem() subscribe to InitEntityEvent.

Unfortunately, I cannot decide for you how to initialize your entities. I think the cookbook examples demonstrate the possible solutions.

Thank you Konstantin.
The problem was solved with Datasource Listeners:
https://doc.cuba-platform.com/manual-6.9/datasource_listeners.html?_ga=2.169616099.314702957.1549179279-1125178118.1543600709