Skip to content

Validation Annotations


@Validation is repeatable (via @Validations). It defines a cross-field validation rule on a class. The condition expression is evaluated after all fields are set; if it returns true the validation fails and the error message is shown on fieldId.

@Repeatable(Validations.class)
@Retention(RetentionPolicy.RUNTIME)
public @interface Validation {
String condition(); // expression that returns true when validation FAILS
String fieldId(); // field to mark as invalid
String message(); // error message to display
}
AttributeTypeDescription
conditionStringSpEL or JS expression evaluated against the form data. Returns true to indicate a validation failure.
fieldIdStringThe field that will show the error message when the condition is met.
messageStringHuman-readable error message shown next to the field.
@Validation(
condition = "endDate != null && startDate != null && endDate < startDate",
fieldId = "endDate",
message = "End date must be on or after start date"
)
public class DateRangeForm {
LocalDate startDate;
LocalDate endDate;
}

Multiple validations are stacked on the same class:

@Validation(condition = "endDate != null && startDate != null && endDate < startDate",
fieldId = "endDate", message = "End date must be on or after start date")
@Validation(condition = "amount != null && amount <= 0",
fieldId = "amount", message = "Amount must be positive")
public class BookingForm {
LocalDate startDate;
LocalDate endDate;
double amount;
}

Container annotation for multiple @Validation entries on the same class. Created automatically by the compiler when you stack @Validation — you rarely use it directly.

@Retention(RetentionPolicy.RUNTIME)
public @interface Validations {
Validation[] value();
}

@Rule is repeatable (via @Rules). It defines a conditional UI rule that runs entirely on the client side: when filter matches, the specified action is applied to a field’s attribute — visibility, value, CSS class, and more — without a server round-trip.

@Repeatable(Rules.class)
@Retention(RetentionPolicy.RUNTIME)
public @interface Rule {
String filter(); // condition expression that activates this rule
RuleAction action(); // what to do when filter matches
String fieldName(); // target field
RuleFieldAttribute fieldAttribute(); // which attribute to modify
String value(); // static value to set
String expression(); // dynamic expression to evaluate
String actionId(); // action to trigger (for RunAction)
RuleResult result(); // Continue or Stop processing further rules
}
AttributeTypeDescription
filterStringCondition expression. Rule activates when this evaluates to true.
actionRuleActionWhat to do: set a value, run an action, change appearance, etc.
fieldNameStringThe field to target.
fieldAttributeRuleFieldAttributeWhich attribute of the field to change.
valueStringStatic value to assign to the attribute.
expressionStringDynamic expression whose result is assigned to the attribute.
actionIdStringName of the action to invoke (used with RunAction).
resultRuleResultContinue to keep evaluating subsequent rules, Stop to halt.
ValueDescription
SetDataValueSet a field’s data value
SetAppDataValueSet a value in the application-level data store
SetAppStateValueSet a value in the application-level state store
SetAttributeValueModify a field’s metadata attribute (see RuleFieldAttribute)
SetStateValueSet a value in the component’s state
RunActionInvoke a named server-side action
RunJSExecute a JavaScript snippet on the client
SetCssClassAdd or remove a CSS class on the field
SetStyleApply inline style to the field
ValueDescription
requiredWhether the field is required
disabledWhether the field is disabled
hiddenWhether the field is hidden
patternInput pattern constraint
minValueMinimum numeric value
maxValueMaximum numeric value
minLengthMinimum string length
maxLengthMaximum string length
cssCSS class(es) applied to the field
styleInline style applied to the field
themeComponent theme variant
errorMessageCustom error message
descriptionHelp / description text
noneNo attribute modification (used with RunAction / RunJS)
ValueDescription
ContinueKeep evaluating subsequent @Rule annotations after this one
StopStop processing further rules once this one fires

Container annotation for multiple @Rule entries on the same class. Created automatically by the compiler.

@Retention(RetentionPolicy.RUNTIME)
public @interface Rules {
Rule[] value();
}

A date-range booking form that cross-validates dates with @Validation and hides the discount field unless the booking is marked as corporate with @Rule:

@Validation(
condition = "endDate != null && startDate != null && endDate < startDate",
fieldId = "endDate",
message = "End date must be on or after start date"
)
@Rule(
filter = "corporate == true",
action = RuleAction.SetAttributeValue,
fieldName = "discountCode",
fieldAttribute = RuleFieldAttribute.hidden,
value = "false",
expression = "",
actionId = "",
result = RuleResult.Continue
)
@Rule(
filter = "corporate == false || corporate == null",
action = RuleAction.SetAttributeValue,
fieldName = "discountCode",
fieldAttribute = RuleFieldAttribute.hidden,
value = "true",
expression = "",
actionId = "",
result = RuleResult.Continue
)
public class BookingForm {
@NotNull
LocalDate startDate;
@NotNull
LocalDate endDate;
boolean corporate;
String discountCode; // only visible for corporate bookings
}