Brightspot CMS Developer Guide

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"
}

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.

Previous Topic
Persistence APIs
Next Topic
Data modeling annotations
Was this topic helpful?
Thanks for your feedback.
The elements that get you up and running in a matter of days, from pre-built content types, to modules, to landing pages.

Content types
Modules
Landing pages
Everything you need to manage and administer content within Brightspot CMS, including plug-and-play integrations.

Dashboards
Authoring content
Workflows
Admin configurations
A guide for installing, supporting and administering code on the Brightspot platform, including integrations requiring developer support to use.

Field types
Content modeling
Rich-text elements
Images