Java Command Annotations – @Pattern
Java command annotations are used for the developing Java commands in PAK.
This chapter describes the functionality of the @Pattern
annotation.
It also gives an example of how you can use this annotation in your implementation.
1. Basics
The @Pattern
annotation restricts the allowed values of a variable to those that match the specified regex pattern.
This annotation is evaluated at runtime and raises an exception at the latest.
This annotation is only applicable for variables that are annotated with @Persistent and of type String.
|
2. Properties
There are two properties defined for the @Pattern
annotation that will be explained in the following.
3. Usage
Listing 1 shows how to use the @Pattern
annotation with different regex values and the example
property usage.
@Pattern
annotation/**
* @workflowDocu This command shows how to use the @Persistent annotation.
*/
@JavaCommand
@CommandGroup("Element")
public class GetElement {
/**
* @workflowDocu List of labels to be added, separated by ","
*/
@Pattern(value = "\\w+(,\\w+)*", example = "elem1,elem2") (1)
@Persistent
private String commaSep;
/**
* @workflowDocu Only allow numbers
*/
@Persistent
@Pattern("\\d+") (2)
private String numbers;
[...]
}
1 | Allow comma-separated Strings for variable commaSep |
2 | Only numbers are allowed for the values of variable number |
Figure 1 shows the result of the @Pattern
usage of Listing 1.
As you can see, the regex as well as the example are provided in the documentation information popup.
The frame of the variable remains red as long as no valid value is entered into the text variable, as can be seen in Figure 2.
After the entered value matches the regex the red border disappears like in Figure 3.