in serverless-ui/jwt-stack/src/main/java/com/awssamples/client/create/CreateView.java [82:135]
public void setup() {
root = binder.createAndBindUi(this);
expirationInSeconds.addValidator(new Validator<String>() {
@Override
public int getPriority() {
return 0;
}
@Override
public List<EditorError> validate(Editor<String> editor, String value) {
List<EditorError> errors = new ArrayList<>();
Try<Integer> parseIntTry = Try.of(() -> Integer.parseInt(value));
if (parseIntTry.isFailure()) {
// Failed to parse as an integer, return early since none of the other errors apply
errors.add(new BasicEditorError(editor, value, "Not a valid integer"));
return errors;
}
int intValue = parseIntTry.get();
if (intValue < JwtService.EXPIRATION_IN_SECONDS_MIN) {
// Too low
errors.add(new BasicEditorError(editor, value, "Value is below the minimum [" + JwtService.EXPIRATION_IN_SECONDS_MIN + "]"));
} else if (intValue > JwtService.EXPIRATION_IN_SECONDS_MAX) {
// Too high
errors.add(new BasicEditorError(editor, value, "Value is above the maximum [" + JwtService.EXPIRATION_IN_SECONDS_MAX + "]"));
}
return errors;
// Check to see if the value is valid
/* Can't use this in GWT!
Match(parseIntTry)
.option(
// Failed to parse as an integer
Case($Failure($()), n -> new BasicEditorError(editor, value, "Not a valid integer")),
// Too low
Case($Success($(n -> n < EXPIRATION_IN_SECONDS_MIN)), n -> new BasicEditorError(editor, value, "Value is below the minimum [" + EXPIRATION_IN_SECONDS_MIN + "]")),
// Too high
Case($Success($(n -> n > EXPIRATION_IN_SECONDS_MAX)), n -> new BasicEditorError(editor, value, "Value is above the maximum [" + EXPIRATION_IN_SECONDS_MAX + "]"))
)
// If any error was generated then add them to the error list
.forEach(errors::add);
*/
}
});
expirationInSeconds.validate(true);
enableDisableButtons();
}