这个链接解决了我的问题:Catch PersistenceException or ConstraintViolationException in JBoss AS 7
然后作为一种解决方法,我创建了一个电子邮件验证器并将一个 f:validator 添加到我正在验证的字段中。
@FacesValidator("emailValidator")
public class EmailValidator implements Validator {
public void validate(FacesContext context, UIComponent component,
Object value) throws ValidatorException {
ResourceBundle resourceBundle = ResourceBundle.getBundle("messages",
Locale.ENGLISH);
if (StringUtils.isBlank(value)) {
return;
} else {
try {
InternetAddress emailAddr = new InternetAddress(
value.toString());
emailAddr.validate();
} catch (AddressException ex) {
FacesMessage facesMessage = new FacesMessage();
String message = resourceBundle
.getString("message.error.invalidEmail");
message = MessageFormat.format(message,
getLabel(context, component));
facesMessage.setDetail(message);
facesMessage.setSeverity(FacesMessage.SEVERITY_ERROR);
throw new ValidatorException(facesMessage);
}
}
}
将此添加到您正在验证的字段中。
<f:validator for="#{cc.attrs.id}_text" validatorId="emailValidator"></f:validator>