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.
Our robust, flexible Design System provides hundreds of pre-built components you can use to build the presentation layer of your dreams.

Asset types
Module types
Page types
Brightspot is packaged with content types that get you up and running in a matter of days, including assets, modules and landing pages.

Content types
Modules
Landing pages
Everything you need to know when creating, managing, and administering content within Brightspot CMS.

Dashboards
Publishing
Workflows
Admin configurations
A guide for installing, supporting, extending, modifying and administering code on the Brightspot platform.

Field types
Content modeling
Rich-text elements
Images
A guide to configuring Brightspot's library of integrations, including pre-built options and developer-configured extensions.

Google Analytics
Shopify
Apple News