title: Make JSF access a Map<String, ?> values from an EL instead of a bean fields?
body: <p>Is there any proper way to override the way JSF accesses the beans fields from an Expression Language? The idea is to mimic this behavior in order to access a <code>Map&lt;String, ?&gt;</code> values, where the bean fields would be the map keys.</p>
  
  <p>In other words, is it possible anyhow to use <code>#{beanContainingNestedMap.keyOfSaidNestedMap}</code>, just as if <code>keyOfSaidNestedMap</code> were a field of the <code>beanContainingNestedMap</code>?</p>
  
  <p>If not, what other solution may I have?</p>
  
  <hr>
  
  <p><strong>Example:</strong></p>
  
  <p><em>Holder.java</em></p>
  
  <pre class="lang-java prettyprint-override"><code>public class Holder {
  
      private Map&lt;String, Object&gt; objects = new HashMap&lt;String, Object&gt;();
  
      public void add(String key, Object value) {
          objects.put(key, value);
      }
  
      public Object getObject(String key) {
          return objects.get(key);
      }
  
  }
  </code></pre>
  
  <p><em>ExampleBean.java</em></p>
  
  <pre class="lang-java prettyprint-override"><code>public class ExampleBean {
  
      private Holder holder = new Holder();
  
      public ExampleBean() {
          holder.add("foo", 42);
          holder.add("bar", 'X');
      }
  
      public Holder getHolder() {
          return holder;
      }
  
  }
  </code></pre>
  
  <p><em>example.xhtml</em></p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;c:out value="#{exampleBean.holder.foo}" /&gt; &lt;!-- should print "42" --&gt;
  &lt;c:out value="#{exampleBean.holder.bar}" /&gt; &lt;!-- should print "X" --&gt;
  </code></pre>
  
  <hr>
  
  <p>What would be great is if I could do something like (kind of pseudo-code since I don't know if such a method exists <code>;)</code>):</p>
  
  <pre class="lang-java prettyprint-override"><code>@Override // override JSF's (if any...)
  public Object resolveEl(String el) {
      try {
          super.resolveEl(el);
      } catch (ElException e) {
          Object bean = e.getBean();
          String fieldName = e.getFieldName();
          if (bean instanceof Holder) {
              Holder holder = (Holder) bean;
              Object value = holder.getObject(fieldName);
              if (value == null) {
                  throw e;
              } else {
                  return value;
              }
          }
      }
  }
  </code></pre>