On 15 October 2015 at 18:54, Cesar Lugo <[email protected]> wrote:
> Hello. I am trying to create a custom list that shows within an object
> form.
> I understand this is called a Contribution in the Apache ISIS programming
> model. I tried with the code below(trying first with a simple list
> returning
> all instances). The Action with the list is not shown, nor the list. Only
> the AddItem list is shown. Am I missing something to make it properly work?
>
>
>
Yes. Contributions act upon the parameters, so there needs to be at least
one parameter. It works like this:
- contributed action of N args... will be rendered as a contributed action
of N-1 args
- contributed association corresponds to a domain service action that takes
exactly one parameter, and must have SAFE semantics
>
> //region > allItems (action)
> @Action(semantics = SemanticsOf.SAFE)
> @ActionLayout(contributed = Contributed.AS_ASSOCIATION)
> @CollectionLayout(render = RenderType.EAGERLY)
> public List<Item> allItems() { return
> container.allInstances(Item.class);}
> //endregion
>
>
>
so, to fix this, specify which domain class you want to contribute to, eg:
@Action(semantics = SemanticsOf.SAFE)
@ActionLayout(contributed = Contributed.AS_ASSOCIATION)
@CollectionLayout(render = RenderType.EAGERLY)
public List<Item> allItems(final Customer customer) {
return container.allInstances(Item.class);
}
Note that one can also contribute to interfaces; so in this case an
"ItemHolder" might be a good interface for your contributee domain object
to implement.
By the way, I've coincidentally been working on an alternative to
contributions, something called a "mixin", similar to a trait, inspired by
the DCI pattern of Trygve Reenskaug and Jim Coplien [1]. See for example
[2], [3].
HTH
Dan
[1] http://www.artima.com/articles/dci_vision.html
[2]
https://github.com/incodehq/incode-module-note/blob/master/dom/src/main/java/org/incode/module/note/dom/impl/note/Notable_addNote.java
[3]
https://github.com/incodehq/incode-module-commchannel/blob/master/dom/src/main/java/org/incode/module/commchannel/dom/impl/channel/CommunicationChannelOwner_communicationChannels.java
>