Object Labels

Dari uses the Record.getLabel method to to construct a displayable label for retrieved objects. By default, the method uses the value of the first field in the class.

For example, if you have this class …

public class Company extends Record {

   private String companyName;
   private String city;
   private String zip;

   ...
}

… an object is labeled with the value of the first field in the class, as in this JSON representation of a Company object:

psddev.dari.test.Company: Chimera, Inc.
{
  "companyName" : "Chimera, Inc.",
  "city" : "Pittsburgh",
  "zip" : "15207",
  "_id" : "0000015b-24fa-d348-a17b-a5ff05000000",
  "_type" : "0000015b-2015-dfff-abdf-f89d49330000"
}

You can override getLabel to customize the object labeling behavior. In the following example, the getLabel override will append the city and zip values to the company name.

public class Company extends Record {

   private String companyName;
   private String city;
   private String zip;

   ...

   @Override
   public String getLabel(){
      return getCompanyName() + " in " + getCity() + " " + getZip();
   }
}

Another way to customize object labels is with the @LabelFields annotation. It specifies one or more field names that are used to construct a displayable label for retrieved objects.

If the class is annotated with @LabelFields

@Recordable.LabelFields({"city", "zip", "companyName"})
public class Company extends Record {

   private String companyName;
   private String city;
   private String zip;

   ...
}

… the values of three fields will be concatenated to generate a label for a Company object:

psddev.dari.test.Company: Pittsburgh 15207 Chimera, Inc.
{
  "companyName" : "Chimera, Inc.",
  "city" : "Pittsburgh",
  "zip" : "15207",
  "_id" : "0000015b-24fa-d348-a17b-a5ff05000000",
  "_type" : "0000015b-2015-dfff-abdf-f89d49330000"
}

Note that the @LabelFields annotation can be used with the @Indexed annotation to enhance searching of Record-derived objects in Brightspot. For more information, see Searching Non-Content Objects.