JSF actionListener gets called although validationFailed from ace:textAreaEntry validator

StackOverflow https://stackoverflow.com/questions/14422602

  •  16-01-2022
  •  | 
  •  

Вопрос

I am using ICEfaces 3.2. I have a validator method defined for a particular ace:textAreaEntry field. If the validation code inside my validator fails I am adding a faces error message to the context. I expected that when this error message gets added to the context, my actionListener would not get executed. But what I notice is that even after adding faces error message to the context from my validator, the actionListener gets executed. I thought that because the validation failed, faces won't execute the actionlistener.

XHTML textareaentry code:

<ace:textAreaEntry
  id="addrincountryofincorp"
  value="#{strformbean.addrInCountryOfIncorp}"
  required="true" styleClass="#{facesContext.validationFailed?'ui-state-error':''}"
  label="Address in Country of Incorporation" cols="50" rows="5"
  validator="#{strformbean.validateAddrLen}" />

Validator method:

public void validateAddrLen(FacesContext fc,UIComponent uc, Object obj){
  int len = 0;
  Map compAttr = uc.getAttributes();
  log.debug("inside validateAddrLen...");
  log.debug("obj = "+obj);
  if(obj !=  null && ! obj.equals("")){
    len = obj.toString().length();
    if(len > 200){
      Utility.addValMesgToContext(compAttr.get("label").toString() + " cannot exceed 200 Characters");
      return;
    }
  }
}
Это было полезно?

Решение

Validation is considered failed only if you actually throw a javax.faces.validator.ValidatorException

Try throwing an Exception with the FacesMessage inside:

FacesMessage msg = new FacesMessage("my validaton message");
msg.setSeverity(FacesMessage.SEVERITY_ERROR);
throw new ValidatorException(msg);
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top