| <!DOCTYPE html> |
| <html lang="en"> |
| <head> |
| <meta charset="utf-8"> |
| <meta name="viewport" content="width=device-width,initial-scale=1"> |
| <title>Drop Downs and Defaults :: Apache Isis</title> |
| <link rel="canonical" href="https://isis.apache.org/userguide/2.0.0-M5/fun/drop-downs-and-defaults.html"> |
| <meta name="generator" content="Antora 2.3.4"> |
| <link rel="stylesheet" href="../../../_/css/site.css"> |
| <link rel="stylesheet" href="../../../_/css/site-custom.css"> |
| <link href="https://fonts.googleapis.com/css?family=Open+Sans:300,300i,400,400i,700,700i|Raleway:300,400,500,700,800|Montserrat:300,400,700" rel="stylesheet"> |
| <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/docsearch.js@2/dist/cdn/docsearch.min.css"/> |
| <link rel="home" href="https://isis.apache.org" title="Apache Isis"> |
| <link rel="next" href="meta-annotations.html" title="Meta-annotations"> |
| <link rel="prev" href="business-rules.html" title="Business Rules"> |
| </head> |
| <body class="article"> |
| <header class="header"> |
| <nav class="navbar"> |
| <div class="navbar-brand"> |
| <a class="navbar-item" href="https://isis.apache.org"> |
| <span class="icon"> |
| <img src="../../../_/img/isis-logo-48x48.png"></img> |
| </span> |
| <span>Apache Isis</span> |
| </a> |
| <button class="navbar-burger" data-target="topbar-nav"> |
| <span></span> |
| <span></span> |
| <span></span> |
| </button> |
| </div> |
| <div id="topbar-nav" class="navbar-menu"> |
| <a class="navbar-end"> |
| <div class="navbar-item hide-for-print"> |
| <span> |
| <input id="algolia-search-input" placeholder="Search"></span> |
| </span> |
| </div> |
| <div class="navbar-item has-dropdown is-hoverable"> |
| <a class="navbar-link" href="#">Quick Start</a> |
| <div class="navbar-dropdown"> |
| <span class="navbar-item navbar-heading">Starter Apps</span> |
| <a class="navbar-item" href="../../../docs/2.0.0-M5/starters/helloworld.html">Hello World</a> |
| <a class="navbar-item" href="../../../docs/2.0.0-M5/starters/simpleapp.html">Simple App</a> |
| <hr class="navbar-divider"/> |
| <span class="navbar-item navbar-heading">Demos & Tutorials</span> |
| <a class="navbar-item" href="../../../docs/2.0.0-M5/demo/about.html">Demo App</a> |
| <a class="navbar-item" href="https://danhaywood.gitlab.io/isis-petclinic-tutorial-docs/petclinic/1.16.2/intro.html">Petclinic (tutorial)</a> |
| <hr class="navbar-divider"/> |
| <span class="navbar-item navbar-heading">Resources</span> |
| <a class="navbar-item" href="../../../docs/2.0.0-M5/resources/cheatsheet.html">Cheatsheet</a> |
| <a class="navbar-item" href="../../../docs/2.0.0-M5/resources/icons.html">Icons</a> |
| </div> |
| </div> |
| <div class="navbar-item has-dropdown is-hoverable"> |
| <a class="navbar-link" href="#">Guides</a> |
| <div class="navbar-dropdown"> |
| <span class="navbar-item navbar-heading">Development</span> |
| <a class="navbar-item" href="../../../setupguide/2.0.0-M5/about.html">Setup Guide</a> |
| <hr class="navbar-divider"/> |
| <span class="navbar-item navbar-heading">Core</span> |
| <a class="navbar-item" href="../../../userguide/2.0.0-M5/about.html">User Guide</a> |
| <a class="navbar-item" href="../../../refguide/2.0.0-M5/about.html">Reference Guide</a> |
| <a class="navbar-item" href="../../../testing/2.0.0-M5/about.html">Testing Guide</a> |
| </div> |
| </div> |
| <div class="navbar-item has-dropdown is-hoverable"> |
| <a class="navbar-link" href="#">Libraries</a> |
| <div class="navbar-dropdown"> |
| <span class="navbar-item navbar-heading">For Use in Apps</span> |
| <a class="navbar-item" href="../../../subdomains/2.0.0-M5/about.html">Subdomain Libraries</a> |
| <a class="navbar-item" href="../../../valuetypes/2.0.0-M5/about.html">Value Types</a> |
| <hr class="navbar-divider"/> |
| <span class="navbar-item navbar-heading">Integrate between Apps</span> |
| <a class="navbar-item" href="../../../mappings/2.0.0-M5/about.html">Bounded Context Mapping Libraries</a> |
| <hr class="navbar-divider"/> |
| <span class="navbar-item navbar-heading">Other</span> |
| <a class="navbar-item" href="../../../incubator/2.0.0-M5/about.html">Incubator</a> |
| <a class="navbar-item" href="../../../legacy/2.0.0-M5/about.html">Legacy</a> |
| </div> |
| </div> |
| <div class="navbar-item has-dropdown is-hoverable"> |
| <a class="navbar-link" href="#">Components</a> |
| <div class="navbar-dropdown"> |
| <span class="navbar-item navbar-heading">Viewers</span> |
| <a class="navbar-item" href="../../../vw/2.0.0-M5/about.html">Web UI (Wicket)</a> |
| <a class="navbar-item" href="../../../vro/2.0.0-M5/about.html">REST API (Restful Objects)</a> |
| <hr class="navbar-divider"/> |
| <span class="navbar-item navbar-heading">Security</span> |
| <a class="navbar-item" href="../../../security/2.0.0-M5/about.html">Security Guide</a> |
| <hr class="navbar-divider"/> |
| <span class="navbar-item navbar-heading">Persistence</span> |
| <a class="navbar-item" href="../../../pjpa/2.0.0-M5/about.html">JPA (EclipseLink)</a> |
| <a class="navbar-item" href="../../../pjdo/2.0.0-M5/about.html">JDO (DataNucleus)</a> |
| <hr class="navbar-divider"/> |
| <span class="navbar-item navbar-heading">Extensions</span> |
| <a class="navbar-item" href="../../../extensions/2.0.0-M5/about.html">Extensions Catalog</a> |
| </div> |
| </div> |
| <div class="navbar-item has-dropdown is-hoverable"> |
| <a class="navbar-link" href="#">Support</a> |
| <div class="navbar-dropdown"> |
| <span class="navbar-item navbar-heading">Contact</span> |
| <a class="navbar-item" href="../../../docs/2.0.0-M5/support/slack-channel.html">Slack</a> |
| <a class="navbar-item" href="../../../docs/2.0.0-M5/support/mailing-list.html">Mailing Lists</a> |
| <a class="navbar-item" href="https://issues.apache.org/jira/browse/ISIS">JIRA</a> |
| <a class="navbar-item" href="https://stackoverflow.com/questions/tagged/isis">Stack Overflow</a> |
| <hr class="navbar-divider"/> |
| <span class="navbar-item navbar-heading">Releases</span> |
| <a class="navbar-item" href="../../../docs/2.0.0-M5/downloads/how-to.html">Downloads</a> |
| <a class="navbar-item" href="../../../relnotes/2.0.0-M5/about.html">Release Notes</a> |
| <a class="navbar-item" href="../../../docs/2.0.0-M5/archive/1-x.html">Archive (1.x)</a> |
| <hr class="navbar-divider"/> |
| <span class="navbar-item navbar-heading">Framework</span> |
| <a class="navbar-item" href="../../../conguide/2.0.0-M5/about.html">Contributors' Guide</a> |
| <a class="navbar-item" href="../../../comguide/2.0.0-M5/about.html">Committers' Guide</a> |
| <a class="navbar-item" href="../../../core/2.0.0-M5/about.html">Core Design</a> |
| </div> |
| </div> |
| <div class="navbar-item has-dropdown is-hoverable"> |
| <a class="navbar-link" href="#">ASF</a> |
| <div class="navbar-dropdown"> |
| <a class="navbar-item" href="http://www.apache.org/">Apache Homepage</a> |
| <a class="navbar-item" href="https://www.apache.org/events/current-event">Events</a> |
| <a class="navbar-item" href="https://www.apache.org/licenses/">Licenses</a> |
| <a class="navbar-item" href="https://www.apache.org/security/">Security</a> |
| <a class="navbar-item" href="https://www.apache.org/foundation/sponsorship.html">Sponsorship</a> |
| <a class="navbar-item" href="https://www.apache.org/foundation/thanks.html">Thanks</a> |
| <hr class="navbar-divider"/> |
| <a class="navbar-item" href="https://whimsy.apache.org/board/minutes/Isis.html">PMC board minutes</a> |
| </div> |
| </div> |
| <a class="navbar-item" href="../../../docs/2.0.0-M5/about.html"> |
| <span class="icon"> |
| <img src="../../../_/img/home.png"></img> |
| </span> |
| </a> |
| </div> |
| </div> |
| </nav> |
| </header> |
| <div class="body "> |
| <div class="nav-container" data-component="userguide" data-version="2.0.0-M5"> |
| <aside class="nav"> |
| <div class="panels"> |
| <div class="nav-panel-pagination"> |
| <a class="page-previous" rel="prev" href="business-rules.html" title="Business Rules"><span></span></a> |
| <a class="page-next" rel="next" |
| href="meta-annotations.html" title="Meta-annotations"><span></span></a> |
| <!-- |
| page.parent doesn't seem to be set... |
| <a class="page-parent disabled" rel="prev" href="" title="Business Rules"><span></span></a> |
| --> |
| </div> |
| <div class="nav-panel-menu is-active" data-panel="menu"> |
| <nav class="nav-menu"> |
| <h3 class="title"><a href="../about.html">User Guide</a></h3> |
| <ul class="nav-list"> |
| <li class="nav-item" data-depth="0"> |
| <ul class="nav-list"> |
| <li class="nav-item" data-depth="1"> |
| <a class="nav-link" href="concepts-patterns.html">Concepts & Patterns</a> |
| </li> |
| <li class="nav-item" data-depth="1"> |
| <a class="nav-link" href="overview.html">Overview</a> |
| </li> |
| <li class="nav-item" data-depth="1"> |
| <a class="nav-link" href="domain-entities-and-services.html">Domain Entities & Services</a> |
| </li> |
| <li class="nav-item" data-depth="1"> |
| <a class="nav-link" href="object-members.html">Properties, Collections & Actions</a> |
| </li> |
| <li class="nav-item" data-depth="1"> |
| <a class="nav-link" href="ui.html">UI Layout & Hints</a> |
| </li> |
| <li class="nav-item" data-depth="1"> |
| <a class="nav-link" href="business-rules.html">Business Rules</a> |
| </li> |
| <li class="nav-item is-current-page" data-depth="1"> |
| <a class="nav-link" href="drop-downs-and-defaults.html">Drop downs and Defaults</a> |
| </li> |
| <li class="nav-item" data-depth="1"> |
| <a class="nav-link" href="meta-annotations.html">Meta-annotations</a> |
| </li> |
| <li class="nav-item" data-depth="1"> |
| <a class="nav-link" href="view-models.html">View Models</a> |
| </li> |
| <li class="nav-item" data-depth="1"> |
| <a class="nav-link" href="mixins.html">Mixins</a> |
| </li> |
| <li class="nav-item" data-depth="1"> |
| <a class="nav-link" href="modules.html">Modules</a> |
| </li> |
| <li class="nav-item" data-depth="1"> |
| <button class="nav-item-toggle"></button> |
| <a class="nav-link" href="../btb/about.html">Beyond the Basics</a> |
| <ul class="nav-list"> |
| <li class="nav-item" data-depth="2"> |
| <a class="nav-link" href="../btb/i18n.html">i18n</a> |
| </li> |
| <li class="nav-item" data-depth="2"> |
| <a class="nav-link" href="../btb/headless-access.html">Headless Access</a> |
| </li> |
| <li class="nav-item" data-depth="2"> |
| <a class="nav-link" href="../btb/hints-and-tips.html">Hints-n-Tips</a> |
| </li> |
| <li class="nav-item" data-depth="2"> |
| <a class="nav-link" href="../btb/programming-model.html">Programming Model</a> |
| </li> |
| </ul> |
| </li> |
| <li class="nav-item" data-depth="1"> |
| <button class="nav-item-toggle"></button> |
| <span class="nav-text">Extensions</span> |
| <ul class="nav-list"> |
| <li class="nav-item" data-depth="2"> |
| <a class="nav-link" href="../command-log/about.html">Command Log</a> |
| </li> |
| <li class="nav-item" data-depth="2"> |
| <a class="nav-link" href="../command-replay/about.html">Command Replay</a> |
| </li> |
| <li class="nav-item" data-depth="2"> |
| <a class="nav-link" href="../flyway/about.html">Flyway</a> |
| </li> |
| <li class="nav-item" data-depth="2"> |
| <a class="nav-link" href="../model-annotation/about.html">Model Annotation</a> |
| </li> |
| <li class="nav-item" data-depth="2"> |
| <a class="nav-link" href="../quartz/about.html">Quartz</a> |
| </li> |
| </ul> |
| </li> |
| </ul> |
| </li> |
| </ul> |
| </nav> |
| </div> |
| <div class="nav-panel-explore" data-panel="explore"> |
| <div class="context"> |
| <span class="title">User Guide</span> |
| <span class="version">2.0.0-M5</span> |
| </div> |
| <ul class="components"> |
| <li class="component"> |
| <span class="title"> </span> |
| <ul class="versions"> |
| <li class="version is-latest"> |
| <a href="../../../docs/2.0.0-M5/about.html">2.0.0-M5</a> |
| </li> |
| </ul> |
| </li> |
| <li class="component"> |
| <span class="title">BC Mapping Libraries</span> |
| <ul class="versions"> |
| <li class="version is-latest"> |
| <a href="../../../mappings/2.0.0-M5/about.html">2.0.0-M5</a> |
| </li> |
| </ul> |
| </li> |
| <li class="component"> |
| <span class="title">Committers' Guide</span> |
| <ul class="versions"> |
| <li class="version is-latest"> |
| <a href="../../../comguide/2.0.0-M5/about.html">2.0.0-M5</a> |
| </li> |
| </ul> |
| </li> |
| <li class="component"> |
| <span class="title">Contributors' Guide</span> |
| <ul class="versions"> |
| <li class="version is-latest"> |
| <a href="../../../conguide/2.0.0-M5/about.html">2.0.0-M5</a> |
| </li> |
| </ul> |
| </li> |
| <li class="component"> |
| <span class="title">Design Docs</span> |
| <ul class="versions"> |
| <li class="version is-latest"> |
| <a href="../../../core/2.0.0-M5/about.html">2.0.0-M5</a> |
| </li> |
| </ul> |
| </li> |
| <li class="component"> |
| <span class="title">Extensions Catalog</span> |
| <ul class="versions"> |
| <li class="version is-latest"> |
| <a href="../../../extensions/2.0.0-M5/about.html">2.0.0-M5</a> |
| </li> |
| </ul> |
| </li> |
| <li class="component"> |
| <span class="title">Incubator Catalog</span> |
| <ul class="versions"> |
| <li class="version is-latest"> |
| <a href="../../../incubator/2.0.0-M5/about.html">2.0.0-M5</a> |
| </li> |
| </ul> |
| </li> |
| <li class="component"> |
| <span class="title">JDO/DataNucleus</span> |
| <ul class="versions"> |
| <li class="version is-latest"> |
| <a href="../../../pjdo/2.0.0-M5/about.html">2.0.0-M5</a> |
| </li> |
| </ul> |
| </li> |
| <li class="component"> |
| <span class="title">JPA</span> |
| <ul class="versions"> |
| <li class="version is-latest"> |
| <a href="../../../pjpa/2.0.0-M5/about.html">2.0.0-M5</a> |
| </li> |
| </ul> |
| </li> |
| <li class="component"> |
| <span class="title">Legacy Catalog</span> |
| <ul class="versions"> |
| <li class="version is-latest"> |
| <a href="../../../legacy/2.0.0-M5/about.html">2.0.0-M5</a> |
| </li> |
| </ul> |
| </li> |
| <li class="component"> |
| <span class="title">Reference Guide</span> |
| <ul class="versions"> |
| <li class="version is-latest"> |
| <a href="../../../refguide/2.0.0-M5/about.html">2.0.0-M5</a> |
| </li> |
| </ul> |
| </li> |
| <li class="component"> |
| <span class="title">Release Notes</span> |
| <ul class="versions"> |
| <li class="version is-latest"> |
| <a href="../../../relnotes/2.0.0-M5/about.html">2.0.0-M5</a> |
| </li> |
| </ul> |
| </li> |
| <li class="component"> |
| <span class="title">REST API (Restful Objects Viewer)</span> |
| <ul class="versions"> |
| <li class="version is-latest"> |
| <a href="../../../vro/2.0.0-M5/about.html">2.0.0-M5</a> |
| </li> |
| </ul> |
| </li> |
| <li class="component"> |
| <span class="title">Security Guide</span> |
| <ul class="versions"> |
| <li class="version is-latest"> |
| <a href="../../../security/2.0.0-M5/about.html">2.0.0-M5</a> |
| </li> |
| </ul> |
| </li> |
| <li class="component"> |
| <span class="title">Setup Guide</span> |
| <ul class="versions"> |
| <li class="version is-latest"> |
| <a href="../../../setupguide/2.0.0-M5/about.html">2.0.0-M5</a> |
| </li> |
| </ul> |
| </li> |
| <li class="component"> |
| <span class="title">Subdomains Catalog</span> |
| <ul class="versions"> |
| <li class="version is-latest"> |
| <a href="../../../subdomains/2.0.0-M5/about.html">2.0.0-M5</a> |
| </li> |
| </ul> |
| </li> |
| <li class="component"> |
| <span class="title">Testing Guide</span> |
| <ul class="versions"> |
| <li class="version is-latest"> |
| <a href="../../../testing/2.0.0-M5/about.html">2.0.0-M5</a> |
| </li> |
| </ul> |
| </li> |
| <li class="component"> |
| <span class="title">Tooling</span> |
| <ul class="versions"> |
| <li class="version is-latest"> |
| <a href="../../../tooling/2.0.0-M5/about.html">2.0.0-M5</a> |
| </li> |
| </ul> |
| </li> |
| <li class="component is-current"> |
| <span class="title">User Guide</span> |
| <ul class="versions"> |
| <li class="version is-current is-latest"> |
| <a href="../about.html">2.0.0-M5</a> |
| </li> |
| </ul> |
| </li> |
| <li class="component"> |
| <span class="title">Value Types Catalog</span> |
| <ul class="versions"> |
| <li class="version is-latest"> |
| <a href="../../../valuetypes/2.0.0-M5/about.html">2.0.0-M5</a> |
| </li> |
| </ul> |
| </li> |
| <li class="component"> |
| <span class="title">Web UI (Wicket Viewer)</span> |
| <ul class="versions"> |
| <li class="version is-latest"> |
| <a href="../../../vw/2.0.0-M5/about.html">2.0.0-M5</a> |
| </li> |
| </ul> |
| </li> |
| </ul> |
| </div> |
| </div> |
| </aside> |
| </div> |
| <main role="main"> |
| <div class="toolbar" role="navigation"> |
| <button class="nav-toggle"></button> |
| <a href="../../../docs/2.0.0-M5/about.html" class="home-link"></a> |
| <nav class="breadcrumbs" aria-label="breadcrumbs"> |
| <ul> |
| <li><a href="../about.html">User Guide</a></li> |
| <li><a href="drop-downs-and-defaults.html">Drop downs and Defaults</a></li> |
| </ul> |
| </nav> |
| <div class="edit-this-page"><a href="https://github.com/apache/isis/edit/2.0.0-M5/antora/components/userguide/modules/fun/pages/drop-downs-and-defaults.adoc">Edit</a></div> |
| </div> |
| <article class="doc"> |
| <a name="section-top"></a> |
| <h1 class="page">Drop Downs and Defaults</h1> |
| <div id="preamble"> |
| <div class="sectionbody"> |
| <div class="paragraph"> |
| <p>Invoking an action whose parameters are primitives or values (int, date, string etc) is simple: the user can just type in or use a date picker. |
| Invoking an action with a parameter of reference type (such as <code>Customer</code> or <code>Order</code>) requires the viewer to provide some mechanism by which the end-user can select the relevant instance.</p> |
| </div> |
| <div class="paragraph"> |
| <p>If the list of available options is fixed then the developer can provided a list a <a href="../../../refguide/2.0.0-M5/applib-methods/prefixes.html#choices" class="page">choices…​()</a> supporting method (for either and action parameter or when editing a property). |
| These are rendered in a drop-down.</p> |
| </div> |
| <div class="paragraph"> |
| <p>If the list of available options is much larger, then the developer can use an <a href="../../../refguide/2.0.0-M5/applib-methods/prefixes.html#autoComplete" class="page">autoComplete…​()</a> supporting method. |
| The user user enters a few characters and this is used to search for matching reference(s), again rendered in a drop-down.</p> |
| </div> |
| <div class="paragraph"> |
| <p>Similarly, when invoking an action, there may well be suitable defaults for the action arguments. |
| For example, if placing an <code>Order</code> then — even if the <code>Product</code> argument might not have a sensible default — the quantity argument could reasonably be defaulted to 1. |
| Or, the <code>Product</code> might indeed have a default, say the product previously placed by this user. |
| The developer indicates this using a <a href="../../../refguide/2.0.0-M5/applib-methods/prefixes.html#default" class="page">default…​()</a> supporting method.</p> |
| </div> |
| </div> |
| </div> |
| <div class="sect1"> |
| <h2 id="choices-and-default"><a class="anchor" href="#choices-and-default"></a>Choices and Default</h2> |
| <div class="sectionbody"> |
| <div class="paragraph"> |
| <p>For example, <em>choices</em> for a property are specified using:</p> |
| </div> |
| <div class="listingblock"> |
| <div class="content"> |
| <pre class="highlightjs highlight"><code class="language-java hljs" data-lang="java">import lombok.Getter; |
| import lombok.Setter; |
| |
| @Property(editing = Editing.ENABLED) <i class="conum" data-value="1"></i><b>(1)</b> |
| @Getter @Setter |
| private String paymentMethod; |
| |
| public List<String> choicesPaymentMethod() { <i class="conum" data-value="2"></i><b>(2)</b> |
| return Arrays.asList("Visa", "Mastercard", "Amex"); |
| }</code></pre> |
| </div> |
| </div> |
| <div class="colist arabic"> |
| <table> |
| <tr> |
| <td><i class="conum" data-value="1"></i><b>1</b></td> |
| <td>If required; properties are by default disabled globally.</td> |
| </tr> |
| <tr> |
| <td><i class="conum" data-value="2"></i><b>2</b></td> |
| <td>Note the "choices" prefix and the suffix matching up with the getter. |
| The method must return a collection of the same type as the property.</td> |
| </tr> |
| </table> |
| </div> |
| <div class="paragraph"> |
| <p>For an action the <em>choices</em> and a suitable <em>default</em> method would be:</p> |
| </div> |
| <div class="listingblock"> |
| <div class="content"> |
| <pre class="highlightjs highlight"><code class="language-java hljs" data-lang="java">public Order changePaymentMethod(String paymentMethod) { |
| setPaymentMethod(paymentMethod); |
| return this; |
| } |
| |
| public List<String> choices0ChangePaymentMethod() { <i class="conum" data-value="1"></i><b>(1)</b> |
| return Arrays.asList("Visa", "Mastercard", "Amex"); |
| } |
| public String default0ChangePaymentMethod() { <i class="conum" data-value="2"></i><b>(2)</b> |
| return getPaymentMethod(); <i class="conum" data-value="3"></i><b>(3)</b> |
| }</code></pre> |
| </div> |
| </div> |
| <div class="colist arabic"> |
| <table> |
| <tr> |
| <td><i class="conum" data-value="1"></i><b>1</b></td> |
| <td>"choices" prefix, N-th param, suffix matches up with the action’s name.<br> |
| Returns a collection of the same type as the parameter.</td> |
| </tr> |
| <tr> |
| <td><i class="conum" data-value="2"></i><b>2</b></td> |
| <td>"default" prefix, N-th param, the suffix matches up with the action’s name.<br> |
| Returns object of same type as parameter.</td> |
| </tr> |
| <tr> |
| <td><i class="conum" data-value="3"></i><b>3</b></td> |
| <td>Common idiom to return the current value of an property of the object.</td> |
| </tr> |
| </table> |
| </div> |
| </div> |
| </div> |
| <div class="sect1"> |
| <h2 id="autocomplete"><a class="anchor" href="#autocomplete"></a>AutoComplete</h2> |
| <div class="sectionbody"> |
| <div class="paragraph"> |
| <p>The <em>autocomplete</em> is similar to <em>choices</em>, but accepts a string parameter, to search for matching results. |
| A property for example might have:</p> |
| </div> |
| <div class="listingblock"> |
| <div class="content"> |
| <pre class="highlightjs highlight"><code class="language-java hljs" data-lang="java">@Property(editing = Editing.ENABLED) <i class="conum" data-value="1"></i><b>(1)</b> |
| @Getter @Setter |
| private Product product; |
| |
| public List<Product> autoCompleteProduct( <i class="conum" data-value="2"></i><b>(2)</b> |
| @MinLength(2) String search) { <i class="conum" data-value="3"></i><b>(3)</b> |
| return productRepository.findByReferenceOrName(search); |
| }</code></pre> |
| </div> |
| </div> |
| <div class="colist arabic"> |
| <table> |
| <tr> |
| <td><i class="conum" data-value="1"></i><b>1</b></td> |
| <td>If required; properties are by default disabled globally.</td> |
| </tr> |
| <tr> |
| <td><i class="conum" data-value="2"></i><b>2</b></td> |
| <td>"autoComplete" prefix, suffix matches property name.<br> |
| Returns a collection of the property’s type.</td> |
| </tr> |
| <tr> |
| <td><i class="conum" data-value="3"></i><b>3</b></td> |
| <td>The <code>@MinLength(…​)</code> annotation indicates the minimum number of characters that must be entered before a search is initiated.</td> |
| </tr> |
| </table> |
| </div> |
| <div class="paragraph"> |
| <p>Actions are very similar:</p> |
| </div> |
| <div class="listingblock"> |
| <div class="content"> |
| <pre class="highlightjs highlight"><code class="language-java hljs" data-lang="java">public Order changeProduct(Product product) { |
| setProduct(product); |
| return this; |
| } |
| |
| public List<Product> autoComplete0Product( <i class="conum" data-value="1"></i><b>(1)</b> |
| @MinLength(2) String search) { |
| return productRepository.findByReferenceOrName(search); |
| }</code></pre> |
| </div> |
| </div> |
| <div class="colist arabic"> |
| <table> |
| <tr> |
| <td><i class="conum" data-value="1"></i><b>1</b></td> |
| <td>"autoComplete" prefix, N-th param, suffix matches action name.<br> |
| Returns a collection of the parameters type.</td> |
| </tr> |
| </table> |
| </div> |
| <div class="paragraph"> |
| <p>An <em>autoComplete</em> method can be used in conjunction with a <em>default</em> method, but it doesn’t make sense to provide both an <em>autoComplete</em> and a <em>choices</em> method.</p> |
| </div> |
| </div> |
| </div> |
| <div class="sect1"> |
| <h2 id="globally-defined-drop-downs"><a class="anchor" href="#globally-defined-drop-downs"></a>"Globally" defined drop-downs</h2> |
| <div class="sectionbody"> |
| <div class="paragraph"> |
| <p>Very often the set of available choices depends on the data type of the property/action parameter, rather than the individual property/parameter itself. |
| And similarly the algorithm to search for references again may well depend only on that reference type.</p> |
| </div> |
| <div class="paragraph"> |
| <p>In the case of <em>choices</em>, annotating a class as "bounded" (as in a "bounded" or fixed number of instances) means that a <em>choices</em> drop-down will automatically be defined. |
| For example:</p> |
| </div> |
| <div class="listingblock"> |
| <div class="content"> |
| <pre class="highlightjs highlight"><code class="language-java hljs" data-lang="java">@DomainObject( |
| bounded = true |
| ) |
| public class Product { /* ... */ }</code></pre> |
| </div> |
| </div> |
| <div class="paragraph"> |
| <p>For more on this, see <a href="../../../refguide/2.0.0-M5/applib/index/annotation/DomainObject.html#bounding" class="page">@DomainObject#bounding</a>.</p> |
| </div> |
| <div class="paragraph"> |
| <p>Or, if the data type is an enum, then a drop-down will be provided automatically. |
| A payment method is a good example of this:</p> |
| </div> |
| <div class="listingblock"> |
| <div class="content"> |
| <pre class="highlightjs highlight"><code class="language-java hljs" data-lang="java">public enum PaymentMethod { |
| VISA, MASTERCARD, AMEX; |
| }</code></pre> |
| </div> |
| </div> |
| <div class="paragraph"> |
| <p>Something similar can be achieved for <em>autoComplete</em>. |
| Here the domain object indicates a repository query to execute. |
| For example:</p> |
| </div> |
| <div class="listingblock"> |
| <div class="content"> |
| <pre class="highlightjs highlight"><code class="language-java hljs" data-lang="java">@DomainObject( |
| autoCompleteRepository = Customers.class, |
| autoCompleteAction = "findByReferenceOrName" |
| ) |
| public class Customer { /* ... */ }</code></pre> |
| </div> |
| </div> |
| <div class="paragraph"> |
| <p>with:</p> |
| </div> |
| <div class="listingblock"> |
| <div class="content"> |
| <pre class="highlightjs highlight"><code class="language-java hljs" data-lang="java">@DomainService(nature = NatureOfService.VIEW) |
| public class Customers { |
| @Action(semantics=SemanticsOf.SAFE) |
| public List<Customer> findByReferenceOrName(@MinLength(3) String refOrName) { |
| ... |
| } |
| }</code></pre> |
| </div> |
| </div> |
| <div class="paragraph"> |
| <p>For more on this, see <a href="../../../refguide/2.0.0-M5/applib/index/annotation/DomainObject.html#autoCompleteRepository" class="page">@DomainObject#autoCompleteRepository</a>.</p> |
| </div> |
| <div class="admonitionblock tip"> |
| <table> |
| <tr> |
| <td class="icon"> |
| <i class="fa icon-tip" title="Tip"></i> |
| </td> |
| <td class="content"> |
| <div class="paragraph"> |
| <p>There’s no need for the nominated method to be an actual action; any method of any domain service will do, so long as it accepts a string and returns the correct list.</p> |
| </div> |
| </td> |
| </tr> |
| </table> |
| </div> |
| </div> |
| </div> |
| <div class="sect1"> |
| <h2 id="multi-select-action-parameters"><a class="anchor" href="#multi-select-action-parameters"></a>Multi-select action parameters</h2> |
| <div class="sectionbody"> |
| <div class="paragraph"> |
| <p>As well as scalar values, action parameters can also be collections. |
| For this to be valid, a <em>choices</em> or <em>autoComplete</em> supporting method must be provided.</p> |
| </div> |
| <div class="paragraph"> |
| <p>For example, suppose we want to "tag" or "label" an object:</p> |
| </div> |
| <div class="listingblock"> |
| <div class="content"> |
| <pre class="highlightjs highlight"><code class="language-java hljs" data-lang="java">public StoryCard tag(List<Tag> tags) { |
| getTags().addAll(tags); |
| } |
| |
| public List<Tag> autoCompleteTag(@MinLength(1) search) { |
| return tagRepository.findByName(search); |
| }</code></pre> |
| </div> |
| </div> |
| <div class="paragraph"> |
| <p>If the action has been associated with a collection, using <a href="../../../refguide/2.0.0-M5/applib/index/annotation/Action.html#associateWith" class="page">@Action#associateWith()</a>, then the collection can be used to provide a list of candidate values.</p> |
| </div> |
| <div class="paragraph"> |
| <p>The <a href="../../../vw/2.0.0-M5/about.html" class="page">Web UI (Wicket viewer)</a> handles this by rendering checkboxes against the associated collection; the user can select/deselect these checkboxes and the selected items are taken as the values for the multi-select action.</p> |
| </div> |
| </div> |
| </div> |
| <div class="sect1"> |
| <h2 id="dependent-choices-for-action-parameters"><a class="anchor" href="#dependent-choices-for-action-parameters"></a>Dependent choices for action parameters</h2> |
| <div class="sectionbody"> |
| <div class="paragraph"> |
| <p>For action it is also possible (in a limited form) to define dependencies between parameters. |
| Specifically, if one parameter is a drop-down choice, then other drop-down choices can be derived from it.</p> |
| </div> |
| <div class="paragraph"> |
| <p>A good example is a category/sub-category:</p> |
| </div> |
| <div class="listingblock"> |
| <div class="content"> |
| <pre class="highlightjs highlight"><code class="language-java hljs" data-lang="java">public ToDoItem categorize( |
| Category category, |
| Subcategory subcategory) { |
| setCategory(category); |
| setSubcategory(subcategory); |
| } |
| |
| public List<Category> choices0Categorize() { |
| return categoryRepository.allCategories(); |
| } |
| public List<Subcategory> choices1Categorize( <i class="conum" data-value="1"></i><b>(1)</b> |
| Category category) { |
| return subcategoryRepository.findBy(category); |
| }</code></pre> |
| </div> |
| </div> |
| <div class="colist arabic"> |
| <table> |
| <tr> |
| <td><i class="conum" data-value="1"></i><b>1</b></td> |
| <td>Returns a list of choices for the 2nd parameter based on the argument provided for the first.</td> |
| </tr> |
| </table> |
| </div> |
| <div class="paragraph"> |
| <p>p</p> |
| </div> |
| </div> |
| </div> |
| </article> |
| <aside class="article-aside toc hide-for-print" role="navigation"> |
| <p class="toc-title">On this page</p> |
| <div id="article-toc"></div> |
| </aside> |
| </main> |
| </div> |
| <footer class="footer"> |
| <div class="content"> |
| <div class="copyright"> |
| <p> |
| Copyright © 2010~2021 The Apache Software Foundation, licensed under the Apache License, v2.0. |
| <br/> |
| Apache, the Apache feather logo, Apache Isis, and the Apache Isis project logo are all trademarks of The Apache Software Foundation. |
| </p> |
| </div> |
| <div class="revision"> |
| <p>Revision: 2.0.0-M5.20210523-1458</p> |
| </div> |
| </div> |
| </footer> |
| <script src="../../../_/js/site.js"></script> |
| <script async src="../../../_/js/vendor/highlight.js"></script> |
| <script src="../../../_/js/vendor/jquery-3.4.1.min.js"></script> |
| <script src="../../../_/js/vendor/jquery-ui-1.12.1.custom.widget-only.min.js"></script> |
| <script src="../../../_/js/vendor/jquery.tocify.min.js"></script> |
| |
| <script> |
| $(function() { |
| $("#article-toc").tocify( { |
| showEffect: "slideDown", |
| hashGenerator: "pretty", |
| hideEffect: "slideUp", |
| selectors: "h2, h3", |
| scrollTo: 120, |
| smoothScroll: true, |
| theme: "jqueryui", |
| highlightOnScroll: true |
| } ); |
| }); |
| </script> |
| |
| <script src="https://cdn.jsdelivr.net/npm/docsearch.js@2/dist/cdn/docsearch.min.js"></script> |
| <script> |
| function focusSearchInput () { document.querySelector('#algolia-search-input').focus() } |
| var search = docsearch({ |
| appId: '5ISP5TFAEN', |
| apiKey: '0fc51c28b4ad46e7318e96d4e97fab7c', |
| indexName: 'isis-apache-org', |
| inputSelector: '#algolia-search-input', |
| autocompleteOptions: { hint: false, keyboardShortcuts: ['s'] }, |
| debug: false, |
| }).autocomplete |
| search.on('autocomplete:closed', function () { search.autocomplete.setVal() }) |
| focusSearchInput() |
| window.addEventListener('load', focusSearchInput); |
| </script> |
| |
| <!-- |
| docsearch options: |
| https://docsearch.algolia.com/docs/behavior/ |
| --> |
| <!-- |
| https://www.algolia.com/doc/api-reference/api-parameters/ |
| algoliaOptions: { hitsPerPage: 6 }, |
| --> |
| </body> |
| </html> |