Skip to main content

Providing error messages

Brightspot provides convenient APIs for displaying data validation and other error messages on the content edit form.

1
import com.psddev.cms.db.Content;
2
import com.psddev.cms.db.ToolUi;
3
import com.psddev.dari.db.State;
4
5
public class Galaxy extends Content {
6
7
private String name;
8
9
@ToolUi.Note("(light years)")
10
private String distanceFromEarth;
11
12
protected void beforeSave() {
13
try {
14
Float.parseFloat(getDistance());
15
} catch (NumberFormatException e) {
16
State state = getState();
17
state.addError(
18
state.getField("distanceFromEarth"),
19
"Distance must be an integer (1234) or a floating-point number (1234.32)");
20
throw new IllegalArgumentException("Resolve the errors listed below, then click Publish.");
21
}
22
}
23
24
public String getDistance() {
25
return distanceFromEarth;
26
}
27
28
}
  • Declares a field for entering a distance.
  • Performs data validation prior to saving the object. Brightspot provides several callback methods with which you can perform validation.
  • Checks if the editor entered a number.
  • Displays a detailed error message above the field distanceFromEarth.
  • Displays a general error message at the top of the content edit form.

Providing error messages.svg

Was this page helpful?

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.