我正在使用primefaces并使用元素" chips"为了介绍多个电子邮件,我验证了它们的格式,并且我试图改变" bubble"如果验证错误,则为ui-state-error
我的筹码:
<div class="ui-grid-col-1" style="margin-right: 5px;">
<p:chips id="chips" required="true" value="#{Contactos.lista_email}"
placeholder="Email" style="color: red;"
requiredMessage="ERROR: El campo 'Email' es obligatorio"
validator="ValidMail"/>
</div>
我的验证员:
@FacesValidator(value = "ValidMail")
public class validatorMail implements Validator{
private Pattern pattern;
private Matcher matcher;
private static final String EMAIL_PATTERN =
"^[_A-Za-z0-9-\\+]+(\\.[_A-Za-z0-9-]+)*@"
+ "[A-Za-z0-9-]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$";
@Override
public void validate(FacesContext context, UIComponent component,
Object value) throws ValidatorException {
ArrayList<String> aux = (ArrayList<String>) value;
String error = null;
final String EMAIL_PATTERN =
"^[_A-Za-z0-9-\\+]+(\\.[_A-Za-z0-9-]+)*@"
+ "[A-Za-z0-9-]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$";
//Check if user has typed only blank spaces
if(value.toString().trim().isEmpty()){
FacesMessage msg = new FacesMessage("ERROR: Email requiere un formato válido", "Email: requiere un formato válido");
msg.setSeverity(FacesMessage.SEVERITY_ERROR);
throw new ValidatorException(msg);
}
else {
pattern = Pattern.compile(EMAIL_PATTERN);
for (String temp : aux){
boolean valid = this.validate(temp);
if (valid == false){
if (error == null) error = temp;
else error = error + "\n" + temp;
}
}
if (error != null){
chips.setValid(false);
FacesMessage msg = new FacesMessage("ERROR DE FORMATO: "+"\n" + error, " ");
msg.setSeverity(FacesMessage.SEVERITY_ERROR);
chips.setValid(false);
throw new ValidatorException(msg);
}
}
}
全部谢谢
答案 0 :(得分:0)
目前无法设置单独的芯片元素无效。 primefaces组件org.primefaces.component.chips.Chips
在6.1版本中没有提供相应的方法。您当然可以在github上打开功能请求。
目前唯一的方法是将整个组件设置为无效,并在FacesMessage
((UIInput) component).setValid(false);