0 Replies Latest reply on Sep 18, 2008 2:54 PM by Bernix Ning

    SeamELResolver vs javax.el.ELResolver

    Bernix Ning Newbie

      We have a collection of objects(entities) which has their own validation pattern, so we have to develop a custom JSF validator for them.

      The problem is, when we trying to set the validator's property with a EL expression, this expression can not be resolvered exactly, and not getting the correct value in the custom validator.

      I doubt it's because the ELContext can't find the Seam context, so that the seam component can not be resolvered.

      Here's my code:


      public class MyEntity implements Serializable {
          // other fields
          private String valuePattern;
              private String value;
              // getters and setters


      public class RegexValidator implements javax.faces.validator.Validator, Serializable {
              @Logger Log log;
              private String expression;
              private String errorMessage;
              public void validate(FacesContext context, UIComponent component, Object value)
                              throws ValidatorException {
                      log.info(">>>> validating regex [#0]", expression);
                      // compile the regex expression and matches the value
              // setters for the "expression" and "errorMessage"


      <?xml version="1.0"?>
      <!DOCTYPE facelet-taglib PUBLIC
        "-//Sun Microsystems, Inc.//DTD Facelet Taglib 1.0//EN"


      public class MyBean {
              // other business logic
              public List<MyEntity> getMyEntities() {
                      // generate the entities


      <ui:repeat value="#{myBean.myEntities}" var="myEntity">
              <h:inputText value="#{myEntity.value}">
                      <my:validateRegex expression="#{myEntity.valuePattern}">



      The log from the validator is >>>> validating regex [], I guess it's because the expression EL can not be resolvered correctly,
      and I change the code to be:

      <my:validateRegex expression="[a-zA-Z]*"/>

      it works fine.

      then I try:

      public class MyBean {
              // other business logic
              public String getRegex() {
                      return "[0-9]*";
      <my:validateRegex expression="#{myBean.regex}">

      works fine too....

      Then I try to change the faces-config.xml:


      Just doesn't work... the expression still can not be resolvered...

      My project was generated by seam-gen, Seam 2.0.2SP1, JBoss 4.2.2GA.

      how can I resolver this valuePattern exactly in the validator? or may be I should write a tag class? like:

      public class RegexValidatorTag extends ValidatorELTag {
              private ValueExpression expression;
              public Validator createValidator() throws JspException {
                      ELContext elContext = FacesContext.getCurrentInstance().getELContext();
                      // how to use SeamELResolver to resolver the expression here?
                      RegexValidator validator = new RegexValidator();

      Any comments will be greatful,