[PrimeFaces] java.lang.IllegalArgumentException lors de la validation d'un composant Primefaces Calendar
Bonjour,
J'ai un composant Primefaces <p:calendar> qui est censé accepter que des horaires sous la forme HH:mm:ss et qui doit lancer un message d'erreur personnalisé en cas de saisie non conforme, pour ça j'ai créé un Validateur mais je reçois une exception du type :
Code:
1 2
| GRAVE: Servlet.service() for servlet [Faces Servlet] in context with path [/access-control-web] threw exception [Illegal pattern character 'n'] with root cause
java.lang.IllegalArgumentException: Illegal pattern character 'n' |
Voici mon code pour l'interface :
Code:
1 2 3
| <p:calendar id="time" value="#{egressSystemBean.deviceTimeToBeSynchronized}" timeOnly="true">
<f:validator validatorId="TimeValidator" ></f:validator>
</p:calendar> |
Validateur :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
| @FacesValidator("TimeValidator")
public class TimeValidator implements Validator {
private Pattern pattern;
private Matcher matcher;
private static final String HH_MM_SS_PATTERN = "([01]?[0-9]|2[0-3]):[0-5][0-9]";
private static final Logger logger = LoggerFactory.getLogger(TimeValidator.class);
public TimeValidator() {
pattern = Pattern.compile(HH_MM_SS_PATTERN);
}
@Override
public void validate(FacesContext context, UIComponent component, Object value) throws ValidatorException {
matcher = pattern.matcher(value.toString());
if (!matcher.matches()) {
FacesMessage msg = new FacesMessage(MessageUtils.getMessage("timeValidationMsgTitle"), MessageUtils.getMessage("timeValidationMsg"));
msg.setSeverity(FacesMessage.SEVERITY_ERROR);
throw new ValidatorException(msg);
}
}
} |