You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@isis.apache.org by da...@apache.org on 2021/10/05 12:43:12 UTC

[isis] branch ISIS-2873-petclinic updated: ISIS-2783: ex 4.9 optional

This is an automated email from the ASF dual-hosted git repository.

danhaywood pushed a commit to branch ISIS-2873-petclinic
in repository https://gitbox.apache.org/repos/asf/isis.git


The following commit(s) were added to refs/heads/ISIS-2873-petclinic by this push:
     new 43bb95d  ISIS-2783: ex 4.9 optional
43bb95d is described below

commit 43bb95da535b788186ee05e0cab569b82f51db88
Author: Dan Haywood <da...@haywood-associates.co.uk>
AuthorDate: Tue Oct 5 13:43:03 2021 +0100

    ISIS-2783: ex 4.9 optional
---
 .../modules/petclinic/pages/040-pet-entity.adoc    | 37 +++++++++++++++++++++-
 1 file changed, 36 insertions(+), 1 deletion(-)

diff --git a/antora/components/tutorials/modules/petclinic/pages/040-pet-entity.adoc b/antora/components/tutorials/modules/petclinic/pages/040-pet-entity.adoc
index e00ced4..13599de 100644
--- a/antora/components/tutorials/modules/petclinic/pages/040-pet-entity.adoc
+++ b/antora/components/tutorials/modules/petclinic/pages/040-pet-entity.adoc
@@ -896,7 +896,42 @@ public String default0Act() {
 
 === Optional exercise
 
-TODO: use @Action(choicesFrom="pets")
+If we wanted to work with multiple instances of the `pets` collection, we can use the xref:refguide:applib-methods:prefixes.adoc#choices[choices] method using the xref:refguide:applib:index/annotation/Action.adoc#choicesFrom[@Action#choicesFrom] attribute.
+
+Add this mixin to allow multiple ``Pet``s to be removed at the same time:
+
+[source,java]
+.PetOwner_removePets.java
+----
+@Action(
+        semantics = SemanticsOf.IDEMPOTENT,
+        commandPublishing = Publishing.ENABLED,
+        executionPublishing = Publishing.ENABLED,
+        choicesFrom = "pets"                            // <.>
+)
+@ActionLayout(associateWith = "pets", sequence = "2")
+@RequiredArgsConstructor
+public class PetOwner_removePets {                      // <.>
+
+    private final PetOwner petOwner;
+
+    public PetOwner act(final List<Pet> pets) {         // <.>
+        pets.forEach(repositoryService::remove);
+        return petOwner;
+    }
+    public String disableAct() {
+        return petRepository.findByPetOwner(petOwner).isEmpty() ? "No pets" : null;
+    }
+                                                        // <.>
+    @Inject PetRepository petRepository;
+    @Inject RepositoryService repositoryService;
+}
+----
+<.> Results in checkboxes in the table, allowing the user to optionally check one or more instances before invoking the action.
+<.> Renamed as the action now works with a list of ``Pet``s
+<.> Signature changed.
+<.> The `choices` method is removed.
+