title: JSF expression evaluation of attribute tags
body: <p>I have a problem with evaluating EL expressions containing <code>var</code>s created by other tags.</p>
  
  <p>I have a project where I am using a custom validator.</p>
  
  <p><code>public class MyValidator implements Validator, StateHolder</code></p>
  
  <p>I have a tag class associated with it:</p>
  
  <p><code>public class MyValidatorTag extends ValidatorTag</code></p>
  
  <p>this class allows for attribute <code>fieldName</code>, with the appropriate <code>tld</code> file for the tag:</p>
  
  <pre><code>&lt;tag&gt;
      &lt;name&gt;my-validator&lt;/name&gt;
      &lt;tag-class&gt;my.packaga.MyValidatorTag&lt;/tag-class&gt;
      &lt;body-content&gt;JSP&lt;/body-content&gt;
      &lt;description&gt;This is my validator&lt;/description&gt;
      &lt;attribute&gt;
          &lt;name&gt;fieldName&lt;/name&gt;
          &lt;required&gt;true&lt;/required&gt;
          &lt;rtexprvalue&gt;true&lt;/rtexprvalue&gt;
          &lt;type&gt;java.lang.String&lt;/type&gt;
          &lt;description&gt;This is some field I need&lt;/description&gt;
      &lt;/attribute&gt;
  &lt;/tag&gt;
  </code></pre>
  
  <p>So far so good. But this setup doesn't allow one to use JSF EL expressions for attribute value. 
  So the validator class (not tag class) I use this code to evaluate attribute value:</p>
  
  <pre><code>public static String evaluateEl(String expression) {
      String value = null;
      if (expression == null) {
          return "";
      }
      if ((expression.indexOf("#{") != -1)
          &amp;&amp; (expression.indexOf("#{") &lt; expression.indexOf('}'))) {
          Object evaledValue =
              FacesContext.getCurrentInstance().getApplication().createValueBinding(
                  expression).getValue(FacesContext.getCurrentInstance());
          if (evaledValue != null) {
              value = evaledValue.toString();
          } else {
              value = null;
          }
      } else {
          value = expression;
      }
      return value;
  }
  </code></pre>
  
  <p>It is limited to strings, and it works for most EL expressions. Expression <code>Hello #{1 eq 2}</code> will cause the attribute to have value <code>Hello false</code>. 
  But there is a case for which this will not work. Any expression which contains a <code>var</code> created by another tag doesn't work. Datatables, dataiterators and most notably <code>&lt;f:loadBundle&gt;</code>, e.g.</p>
  
  <p><code>&lt;f:loadBundle basename="mypackage.message.ui-strings" var="msgs" /&gt;</code></p>
  
  <p>Followed by an input component containing validator:</p>
  
  <p><code>&lt;cust:my-validator fieldName="#{msgs['myfield1.name']}"&gt;&lt;/cust:my-validator&gt;</code></p>
  
  <p>Fieldname evaluates to empty string using the expression evaluation code above. Changing it to <code>#{requestScope.msgs....</code> doesn't fix the problem. Looking at loadBundle implementation, it adds the var <code>msgs</code> to request scope, so I don't see why vars don't work for me. Please, somebody help me understand.</p>