Uploaded image for project: 'Isis'
  1. Isis
  2. ISIS-1747

Update docs, hints-n-tips for view models



    • Type: Improvement
    • Status: Closed
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 1.15.1
    • Fix Version/s: 1.16.0
    • Component/s: None
    • Labels:


      see https://github.com/incodehq/incode-platform/issues/10


      here's the text that has been removed

        1. Demo App: Highlighting Current

      As a by-the-by, the demo app has one further "trick up its sleeve".
      If you run the app you'll notice that the currently selected `DemoObject` is highlighted in the left-hand table of the `HomePageViewModel`.

      This is accomplished by having the view model collaborate with a subscribing domain service that configures a CSS class.

      We start by ensuring that the `DemoObject` emits an event for its CSS class:

      cssClassUiEvent = DemoObject.CssClassUiEvent.class
      public class DemoObject ... {

      public static class CssClassUiEvent
      extends org.apache.isis.applib.services.eventbus.CssClassUiEvent<DemoObject> {}

      Next, we define the domain service to act as the subscriber.
      Since it will be interact

      public class HomePageViewModel ... {

      @DomainService(nature = NatureOfService.DOMAIN)
      public static class CssHighlighter extends AbstractSubscriber {

      public void on(DemoObject.CssClassUiEvent ev) {
      if(getContext() == null)

      { return; }

      if(ev.getSource() == getContext().getSelected())

      { // <1> ev.setCssClass("selected"); }


      private HomePageViewModel getContext()

      { // <2> return (HomePageViewModel) scratchpad.get("context"); }

      void setContext(final HomePageViewModel homePageViewModel)

      { scratchpad.put("context", homePageViewModel); }

      Scratchpad scratchpad; // <3>
      <1> If the domain object is the currently selected then set the CSS class
      <2> Provide methods to set and get the current `HomePageViewModel` (acting as the context)
      <3> Store the context using the `Scratchpad` domain service (request-scoped so thread-safe).

      The `HomePageViewModel` is responsible for setting itself as the context for the domain service:

      public class HomePageViewModel ... {
      public TranslatableString title()

      { cssHighlighter.setContext(this); // <1> ... }

      CssHighlighter cssHighlighter;
      <1> set the context on the domain service

      Finally we just need some CSS, in the `application.css` file:


      { font-style: italic; font-weight: bolder; }





            • Assignee:
              danhaywood Daniel Keir Haywood
              danhaywood Daniel Keir Haywood
            • Votes:
              0 Vote for this issue
              2 Start watching this issue


              • Created: