CRUD operation with StandardLookup

I have an entity named NetworkShare. “windowCommitAndClose” being used for OK button
If I click on OK button while performing CREATE and EDIT actions, “windowCommitAndClose” will be called.

Editor.xml

<layout expand="editActions" spacing="true">
            <form id="form" dataContainer="networkShareDc">
                <column width="250px">
                    <textField id="advertiserField" property="advertiser"/>
                    <textField id="apiKeyField" property="apiKey"/>
                </column>
            </form>
           <hbox id="editActions" spacing="true">
               <button action="windowCommitAndClose"/>
               <button action="windowClose"/>
            </hbox>

Problem 1: Here windowCommitAndClose method is overwritten. and dataManager commit is committing changes to the database. but the method is not closing the window itself. So calling close(WINDOW_CLOSE_ACTION); explicitly.

Editor screen:

  @Override
    protected void commitAndClose(Action.ActionPerformedEvent event) {
        NetworkShare networkShare = super.getEditedEntity();
        networkShare.setAdvertiser(advertiserField.getValue());
        networkShare.setNetwork(networkField.getValue());
   
        CommitContext commitContext =  new CommitContext(networkShare);
        dataManager.commit(commitContext);
        close(WINDOW_CLOSE_ACTION);
    }

Problem 2) If I perform create operation same method is called “commitAndClose”. but not reflecting changes in the corresponding db.If I modify the WINDOW_COMMIT_AND_CLOSE_ACTION, create operation works fine.
Problem 3) if I perform edit operation with this close(WINDOW_COMMIT_AND_CLOSE_ACTION); is creating 2 entries in the db.

Hello @vedika.joshi

Problem 1: the method is not closing the window itself. So calling close(WINDOW_CLOSE_ACTION); explicitly

You completely redefined behavior of the method so you have to close the window manually.

Problem 2, Problem 3

Could you share more details? Please share test project if possible

Regards,
Daniil

Thankyou for your input.

Now I have changed slightly this function. Instead of close(WINDOW_CLOSE_ACTION); ,I am using close(WINDOW_COMMIT_AND_CLOSE_ACTION);. With this implementation CREATE action works fine. But while doing EDIT operation it is generating 2 entires in the database table. one original and one edited

Could you please let me know how to get rid of the duplicate entry?

 @Override
    protected void commitAndClose(Action.ActionPerformedEvent event) {
        NetworkShare networkShare = super.getEditedEntity();
        networkShare.setAdvertiser(advertiserField.getValue());
        networkShare.setNetwork(networkField.getValue());
   
        CommitContext commitContext =  new CommitContext(networkShare);
        dataManager.commit(commitContext);
        close(WINDOW_COMMIT_AND_CLOSE_ACTION);
    }

Or Where can I find which action ID or trigger point is getting triggered on CREATE and EDIT action? So than I can do different implementation on CREATE trigger and EDIT trigger

I suggest you to change method implementation to the following:

@Override
protected void commitAndClose(Action.ActionPerformedEvent event) {
    // custom logic
    NetworkShare networkShare = super.getEditedEntity();
    networkShare.setAdvertiser(advertiserField.getValue());
    networkShare.setNetwork(networkField.getValue());
   
    // delegate to super
    super.commitAndClose();
}

Regards,
Daniil

Thankyou for your input Daniil!!

    protected void commitAndClose(Action.ActionPerformedEvent event) {
        NetworkShare networkShare = super.getEditedEntity();
        networkShare.setAdvertiser(advertiserField.getValue());
        networkShare.setNetwork(networkField.getValue());
        networkShare.setShareInPercent(shareInPercentField.getValue());
        networkShare.setApiKey(apiKeyField.getValue());
        networkShare.setValidFrom(validFromField.getValue());
        networkShare.setValidTo(validToField.getValue());
        networkShareDc.setItem(networkShare);
        CommitContext commitContext = new CommitContext(networkShare);
        //dataManager.commit(commitContext);
        //close(WINDOW_CLOSE_ACTION);
        super.commitAndClose(event);
    }

This doest not reflect the changes in the database table on edit action.

So I used datamanager.commit(). With this EDIT action works fine. Can see edited values on the screen as well as in the database. Since I am closing the window manually. i.e close(WINDOW_CLOSE_ACTION); But in this case CREATE action doest not reflect the new entry on the screen but can see that entry in the database.