I have this code
<h:inputFile id="id_logo" value="#{organizercontroller.currentLogo}" validator="#{organizercontroller.validateLogo}"/>
<h:message id="id_logo_message" for="id_logo" />
and I want to validate the inputFile with the method validateLogo
.
public void validateLogo(FacesContext context, UIComponent comp, Object value) throws ValidationException {
Part logo = (Part) value;
try (InputStream input = logo.getInputStream()) {
if (input.available() > MAX_UPLOAD_SIZE) {
String message = "Die Datei darf max. " + (int) MAX_UPLOAD_SIZE / 1000000 + " MB betragen";
throw new ValidatorException(new FacesMessage(FacesMessage.SEVERITY_ERROR, message, message));
}
} catch (Exception e) {
e.printStackTrace();
}
}
When I submit my form, the validation message is in my console and not in the <h:message>
tag. What am I doing wrong?