Parameters from menu (flowUI)

In the lastest version of Jmix (FlowUI) I noticed the menu has following options for sending parameters to listView:
image

However, I didn’t find any documentation that explains how to use it.

I have the following use case:

I have a list screen hr_EmplLoanEsApp.list and want to call from two different menus as follows:

  1. An employee user: I want to send an indication that this is opened by an employee. So that the employee’s profile is populated on the screen beforeShow()

I tried the following way to send the parameter value

 <item view="hr_EmplLoanEsApp.list"
              title="msg://com.inteacc.hr.view.pr.emplloanesapp/emplLoanEsAppListView.title">
            <properties>
                <property name="userType" value="employee"/>
            </properties>
        </item>
  1. Human resource team user. For this screen it may be as follows:
 <item view="hr_EmplLoanEsApp.list"
              title="msg://com.inteacc.hr.view.pr.emplloanesapp/emplLoanEsAppListView.title">
            <properties>
                <property name="userType" value="hr"/>
            </properties>
        </item>

Questions for FlowUI project:

  1. Is that the right approach to setting the parameter value?
  2. How can I get the parameter value in my "hr_EmplLoanEsApp.list" screen that was passed in from the menu selected by the user?
  3. Can I get code snipped on the use of “properties”, “Query parameters” and “Route parameters”?

Hi Mortoza!

These properties are used to configure method parameters in BeanMenuItem.
In your case, the best practise is QueryParameters.

First of all, you have to write them in menu.xml.

 <item view="hr_EmplLoanEsApp.list"
              title="msg://com.inteacc.hr.view.pr.emplloanesapp/emplLoanEsAppListView.title">
            <queryParameters>
                <parameter name="userType" value="hr"/>
            </queryParameters>
        </item>

Then, in the ViewController, define the userType parameter and override the beforeEnter method.

    protected String userType;

    @Override
    public void beforeEnter(BeforeEnterEvent event) {
        Map<String, List<String>> parameters = event.getLocation().getQueryParameters().getParameters();
        if (parameters.containsKey("userType")) {
            parameters.get("userType").stream()
                    .findAny()
                    .ifPresent(this::setUserType);
        }

        super.beforeEnter(event);
    }

    public void setUserType(String userType) {
        this.userType = userType;
    }

Now you can use the parameter for your own purposes.

    @Subscribe
    public void onBeforeShow(BeforeShowEvent event) {
        if ("hr".equals(userType)) {
            //do logic
        } else if ("employee".equals(userType)){
            //do logic
        }
    }

Regards,
Dmitriy

1 Like

Hi Dimitriy
Thank you, that works very well.

Unfortunately, in the latest version 2.0.1, it’s not working anymore.

Here you see from where I created the parameters:
image

And see below the xml generated. I share with you the image to show you that “queryParameters” is not recognized (in red):
image

What do you suggest?

Hi, Mortoza
Instead, you should use urlQueryParameters.

However, the menu designer had to suggest the correct snippet.
Linked issue will be reopened: https://youtrack.jmix.io/issue/JST-4019/QueryParameters-migration

1 Like

Thank you. Looking forward to the fix.