Passing collection as parameter with setWindowParams

Hi,

I am trying to pass collection data to the editor screen as parameter when the table action is clicked. I tried to use setWindowParams of the standard actions but the result is unexpected.

For example, in below code i’m trying to pass the collection of order lines to the Order Line editor :


@Override
protected void postInit() {
    orderLinesTableCreate.setWindowParams(ParamsMap.of("orderLines", orderLinesDs.getItems()));
    orderLinesTableEdit.setWindowParams(ParamsMap.of("orderLines", orderLinesDs.getItems()));
}

Problem is the passed collection is null. Appreciate any help for what i’m trying to do. Thanks.

Hi David,

I’ve replicated your code and added the following to OrderLineEdit:


public class OrderLineEdit extends AbstractEditor<OrderLine> {

    @WindowParam
    private Collection<OrderLine> orderLines;
...
    @Override
    public void init(Map<String, Object> params) {
...
        System.out.println("orderLines: " + orderLines);
    }
}

The orderLines field is not null and contains the collection of OrderLine entities on the moment of opening OrderEdit (i.e. when postInit() was called).

What do you want to achieve?

Hi Konstantin,

Yes, it will pass the collection after postinit() is called.

However, when i create a new order line and then edit the new order line (Ok not press yet), the passed collection become null.

I would like to be able to pass the full collection to OrderLineEdit.

Hi David,

I cannot reproduce it, can you attach a sample project here?

Attached is the zip file for the sample project.

Essentially, what i’m trying to do is to implement a check that a Product cannot be entered twice in the same Order. For this, i need to pass the collection of order lines to OrderLineEdit for the validation.

The current behaviour is (which is not what i expected):

  • For new Order, the lines collection will always be null and is not updated after adding some new lines.
  • For existing Order, the lines collection is not updated with newly added new lines.

For the validation to be work, I need the lines collection that includes any added / changed lines.

Sales.zip (94.7K)

Hi David,

When you initialize the parameter in postInit(), it keeps the collection as it was on the moment of screen opening (it’s never null though, just can be empty). So to reflect the current state, the parameter should be initialized right before the action is invoked:


public class OrderEdit extends AbstractEditor<Order> {
...
    @Inject
    private CollectionDatasource<OrderLine, UUID> linesDs;

    @Named("linesTable.create")
    private CreateAction linesTableCreate;

    @Named("linesTable.edit")
    private EditAction linesTableEdit;

    @Override
    public void init(Map<String, Object> params) {
...
        linesTableCreate.setBeforeActionPerformedHandler(() -> {
            linesTableCreate.setWindowParams(ParamsMap.of("lines", linesDs.getItems()));
        });
        linesTableEdit.setBeforeActionPerformedHandler(() -> {
            linesTableEdit.setWindowParams(ParamsMap.of("lines", linesDs.getItems()));
        });
    }

See the project attached.

Sales.zip (94.2K)

1 Like

Ok Thanks! Will solve it with the new before action handler after upgrade to 6.3 (still on 6.2.8).

Hi Konatantin
I am trying to run this app in V6.7 and having the following exception:

:app-core:deploy

:app-gui:compileJavaD:\Studio Projects\demo\Demo-Parameter\modules\gui\src\com\company\sales\gui\order\OrderEdit.java:49: error: incompatible types: bad return type in lambda expression
linesTableCreate.setBeforeActionPerformedHandler(() -> {
^
missing return value
D:\Studio Projects\demo\Demo-Parameter\modules\gui\src\com\company\sales\gui\order\OrderEdit.java:52: error: incompatible types: bad return type in lambda expression
linesTableEdit.setBeforeActionPerformedHandler(() -> {
^
missing return value
Note: Some messages have been simplified; recompile with -Xdiags:verbose to get full output
2 errors
FAILED

the exception is coming from the lines marked below:
image
Is there any breaking change in V6.7?

Hi Mortoza,

The project was created a year ago on platform version 6.1. Since then, the BeforeActionPerformedHandler interface was changed (don’t remember in what version but certainly earlier than 6.7) and its method must return a boolean value indicating whether to execute the action. So the code should be as follows:

        linesTableCreate.setBeforeActionPerformedHandler(() -> {
            linesTableCreate.setWindowParams(ParamsMap.of("lines", linesDs.getItems()));
            return true;
        });
        linesTableEdit.setBeforeActionPerformedHandler(() -> {
            linesTableEdit.setWindowParams(ParamsMap.of("lines", linesDs.getItems()));
            return true;
        });

Thank you very much.