:Notice: Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at. http://www.apache.org/licenses/LICENSE-2.0 . Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR  CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.


(since 1.16)

The framework allows an action to be associated with other properties or
collections of the same domain object. For complete reference see the
https://isis.apache.org/guides/rgant/rgant.html#_rgant-Action_associateWith[Apache
Isis Reference Guide]

We setup a simple `FibonacciNumberVm` class to demonstrate this.

[source,java]
----
@DomainObject
public class DemoItem {

    public String title() {
        return String.format("DemoItem '%s'", getName());
    }

    @Property
    @Getter @Setter private String name;

}
----

Now following demo view model holds `items` a collection of element type
`FibonacciNumberVm`. The action method `doSomethingWithItems(...)` can be thought
of as associated with the `items` collection, because it expresses this
association using the annotation `@Action(associateWith="items")`.

[source,java]
----
@DomainObject(nature=Nature.VIEW_MODEL)
public class AssociatedActionDemo extends DemoStub {

    @Inject MessageService messageService;

    @Getter private final Set<DemoItem> items;

    @Action(associateWith="items")
    public AssociatedActionDemo doSomethingWithItems(Set<DemoItem> items) {
        if(items!=null) {
            items.forEach(item->messageService.informUser(item.getName()));
        }
        return this;
    }

}
----

See the associated action demo
link:${SOURCES_DEMO}/demoapp/dom/actions/assoc[sources].
