Skip to main content

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…

showLineNumbers
1
public class Company extends Record {
2
3
private String companyName;
4
private String city;
5
private String zip;
6
7
}

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

showLineNumbers
1
psddev.dari.test.Company: Chimera, Inc.
2
{
3
"companyName" : "Chimera, Inc.",
4
"city" : "Pittsburgh",
5
"zip" : "15207",
6
"_id" : "0000015b-24fa-d348-a17b-a5ff05000000",
7
"_type" : "0000015b-2015-dfff-abdf-f89d49330000"
8
}

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.

showLineNumbers
1
public class Company extends Record {
2
3
private String companyName;
4
private String city;
5
private String zip;
6
7
@Override
8
public String getLabel() {
9
return getCompanyName() + " in " + getCity() + " " + getZip();
10
}
11
}

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

showLineNumbers
1
@Recordable.LabelFields({"city", "zip", "companyName"})
2
public class Company extends Record {
3
4
private String companyName;
5
private String city;
6
private String zip;
7
8
}

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

showLineNumbers
1
psddev.dari.test.Company: Pittsburgh 15207 Chimera, Inc.
2
{
3
"companyName" : "Chimera, Inc.",
4
"city" : "Pittsburgh",
5
"zip" : "15207",
6
"_id" : "0000015b-24fa-d348-a17b-a5ff05000000",
7
"_type" : "0000015b-2015-dfff-abdf-f89d49330000"
8
}

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.