Cuba 7: Passing Parameters to From Browser- to Edit-Screen

Hi,
in Cuba 6 there was a way to pass a parameter-Map from a browse- to an edit-screen.

Example:

@Named("positionTable.create")   
private CreateAction positionTableCreate;

@Override
public void init(Map<String, Object> params) {

    HashMap<String,Object> hm4PosWindows = new HashMap<>();
    hm4PosWindows.put(ENUM_Names.UEBERGABE_ABF_KOPF_AN_POSITION.name(),   
                                     this.auftragKopfDs);
    hm4PosWindows.put(ENUM_Names.UEBERGABE_ABF_POSLISTE_AN_POSITION.name(), 
                                    this.positionDs);
    positionTableCreate.setWindowParams(hm4PosWindows);


   ....

In Cuba 7 it is possible, to inject the CreateAction in the browsing-Controller, but what is the way to pass a parameter to the called StandardEditor ?

In the manual of Cuba 7 found an hint for passing paramters for programmatic created screens
3.5.3.4.4. Using Screen Parameters in Loaders
But what is the way, when the EditAction/CreateAction … are used ?

Thanks

Found a way:

onCreateBtnClick(Button.ClickEvent event)
and iterated the open screens like

for (Screen s: screens.getOpenedScreens().getActiveScreens()) {

After found the EditScreen i used a simple setter-Method to pass the parameters.

It seems more easy than the old way …

Hi Martin,

Please don’t do this:

for (Screen s: screens.getOpenedScreens().getActiveScreens()) {

In CUBA 7, the standard actions are thin wrappers around screen builders. So instead of injecting/overriding/parameterizing standard actions, just create a custom handler and use the ScreenBuilders API as described in the documentation, for example:

@Subscribe("customersTable.create")
protected void onCustomersTableCreateActionPerformed(Action.ActionPerformedEvent event) {
    CustomerEdit editScreen = screenBuilders.editor(customersTable)
            .newEntity()
            .withScreenClass(CustomerEdit.class)
            .withLaunchMode(OpenMode.DIALOG)
            .build();
    editScreen.setSomeParameter("someValue");
    editScreen.show();
}
1 Like

Hi Konstantin,

ok. Now I understand it. It works.

Thanks

how did you finally passed the parameters? there’s no such method in editScreen as setWindowParams

When you create the CustomerEdit class, you add setters and getters for the parameters you wish to pass into the screen. In the example above, the class will have getters and setters for the someParameter field:

class CustomerEdit extends StandardEditor<Customer> {

    private String someParameter;

    public void setSomeParameter(String param) {

        this.someParameter = param
    }

    public String getSomeParameter() {

        return someParameter;
    }
}

If you look at the example, you call edit.setSomeParameter(…) just before you call edit.show() which will set the parameter in your screen before it appears.

More details here:

https://doc.cuba-platform.com/manual-7.0/opening_screens.html

2 Likes

Is it possible to pass parameters from a 7.x controller StandardEditor to an old 6.x AbstractEditor?
I need to pass parameters to the 6.x collectionDatasource editor screen

Yes, you can do it using MapScreenOptions, for example:

screenBuilders.editor(Foo.class, this)
        .editEntity(foo)
        .withScreenId("myLegacyFooEditor")
        .withOptions(new MapScreenOptions(ParamsMap.of("paramName", paramValue)))
        .build()
        .show();
1 Like