jmix-framework / jmix

Jmix framework
https://www.jmix.io
Apache License 2.0
694 stars 124 forks source link

Instance loader doesn't load without query but has delegate #3796

Open BryanYin opened 1 month ago

BryanYin commented 1 month ago

Environment

Jmix version: <2.3.4>

Bug Description

When instance data loader has no query in XML, but has delegate in controller, it will not load the data.

Steps To Reproduce

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<view xmlns="http://jmix.io/schema/flowui/view"
      title="msg://testBlankView.title">
    <data>
        <instance id="userDc" class="com.company.jmix2sample.entity.User">
            <loader id="userDl"/>
            <fetchPlan extends="_base"/>
        </instance>
    </data>
    <layout>
        <textField dataContainer="userDc" property="username"/>
    </layout>
</view>
public class TestBlankView extends StandardView {
    @Autowired
    private DataManager dataManager;
    @ViewComponent
    private InstanceLoader<User> userDl;

    @Install(to = "userDl", target = Target.DATA_LOADER)
    private User userDlLoadDelegate(final LoadContext<User> loadContext) {
        var user = dataManager.load(User.class)
                .query("select u from jmx2sp_User u where u.username = :username")
                .parameter("username","admin")
                .one();
        //...
        // other processes.
        return user;
    }

    @Subscribe
    public void onReady(final ReadyEvent event) {
        userDl.load(); // easy to set breakpoint and debug
    }
}

Current Behavior

when debugging userDl.load() and step into it, the code returns at:

  if (!needLoad())
      return;

Expected Behavior

When we have delegate for the loader, it should not consider query settings in XML. Because there should be a case the instance is loaded by complex query or native query(this is what I met) that is more convenient to write in Java.

Sample Project

Please see above code, simply create a blank view can reproduce the issue.

Reports that include a sample will take priority over reports that do not.