You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@isis.apache.org by Dan Haywood <da...@haywood-associates.co.uk> on 2012/09/21 10:11:14 UTC

@AutoComplete implemented; idea for a @PersistedTitle annotation.

First, just to say that (per the work that Jeroen and I are doing), I've
implemented support for a new AutoCompleteFacet, defined by the
@AutoComplete annotation.  It works like this:

@AutoComplete(repository=Properties.class, action="autoComplete")
public class Property extends AbstractDomainObject {
   ....
}

which refers to the "autoComplete" action method in the Properties
repository:

public interface Properties {

    @Hidden
    List<Property> autoComplete(String search);
    ...
}


Then, when there's a reference to a Property, the viewer can search for the
AutoCompleteFacet and render some sort of intelligent drop down.  This has
been implemented in the Wicket viewer (will complete this morning, just
need to move into the Isis codebase):

            @Override
            protected List<ObjectAdapterMemento> obtainMementos(String
term) {
                final ObjectSpecification typeOfSpecification =
entityModel.getTypeOfSpecification();
                final AutoCompleteFacet autoCompleteFacet =
typeOfSpecification.getFacet(AutoCompleteFacet.class);
                final List<ObjectAdapter> results =
autoCompleteFacet.execute(term);
                return Lists.transform(results, Mementos.fromAdapter());
            }

You can see the result of this in [1]

~~~

The above support for autocomplete requires that the repository action can
search for something meaningful.  In the example shown, every Property has
a reference code, which is meaningful to the users.  But in other scenarios
there may not be such a convenient attribute to search on; a better thing
to search for might be the title.

However, title isn't a persisted property; it is computed on the fly.

So I intend to implement is for Isis to have a @PersistedTitle annotation.
 This would tell the Isis runtime to automatically update the annotated
property with the title whenever the object is dirtied (just in the same
way that IDs are computed and optimistic timestamps are updated).

For example:

public class Customer {

  @Title(sequence="1", append=" ")
  public String getFirstName() { ... }
  public void setFirstName(String firstName) { ... }

  @Title(sequence="2", append=" ")
  public String getLastName() { ... }
  public void setLastName(String lastName) { ... }

  @PersistedTitle // implies hidden; is written to; don't annotate with
@Title, else infinite loop!
  public String getTitle() { ... }
  public void setTitle(String title) { ... }

}

Then, the autoComplete repository action could query on this persisted
title property.

Thoughts?
Dan


[1]
http://danhaywood.files.wordpress.com/2012/09/isis-wicket-autocomplete.png