Important Notice - Forums is archived
To simplify things and help our users to be more productive, we have archived the current forum and focus our efforts on helping developers on Stack Overflow. You can post new questions on Stack Overflow or join our Discord channel.

Vaadin lets you build secure, UX-first PWAs entirely in Java.
Free ebook & tutorial.
HTML in Error Validation
Hey,
is it possible to use HTML in the ErrorBox?
Thanks
Is it correct to Overwrite getHtmlMessage?
If this is right anyone has an example?
Thx a lot.
I have never tried it, but this is exactly how it says in the API docs:
The default implementation of InvalidValueException does not support HTML in error messages. To enable HTML support, override getHtmlMessage() and use the subclass in validators.
Source: https://vaadin.com/api/com/vaadin/data/Validator.InvalidValueException.html
Ok i have test it i here so it works:
@SuppressWarnings("serial")
public class InvalidValueExceptionHTML extends InvalidValueException {
public InvalidValueExceptionHTML(String message) {
super(message);
}
@Override
public String getHtmlMessage() {
String s = super.getHtmlMessage();
return "<b>" + s + "</b>";
}
}
@SuppressWarnings("serial")
public class IntegerMaxValidator extends AbstractValidator implements Validator {
private int max;
private String eString;
public IntegerMaxValidator(String errorMessage, int max) {
super(errorMessage);
this.eString = errorMessage;
this.max = max;
}
@Override
public boolean isValid(Object value) {
try {
int a = Integer.parseInt(value.toString());
if (a < max) {
return true;
}
} catch (Exception e) {
System.out.println(e.getStackTrace());
return false;
}
IntegerMaxValidator.this.setErrorMessage(eString);
return false;
}
public void validate(Object value) throws InvalidValueException {
if (!isValid(value)) {
String message = getErrorMessage().replace("{0}", String.valueOf(value));
throw new InvalidValueExceptionHTML(message);
}
}
}
know you can call IntegerMaxValidator("<h1>MeineError Message</h1>", 128);
and you become and html parsed Error message.
Thx