title: Auto-generated ids for facelets components
body: <p>We use facelets to create some custom ajaxy components.  One of the behaviours we would like to mimic from the default components is that an id is optional, and an id is generated if it is not passed.  I can already do it like this:</p>
  
  <pre><code>&lt;ui:composition ...&gt;
    &lt;div class="myComponent" id="#{jsfSupport.generateId(id)}"&gt;
       ...
    &lt;/div&gt;
  &lt;/ui:composition&gt;
  </code></pre>
  
  <p>I use JBoss el to call a support method (could use el functions as well):</p>
  
  <pre><code>public class JsfSupport {
  
    public String generateId(String id) {
  
      if (id==null || "".equals(id){
    return FacesContext.getCurrentInstance().getViewRoot().createUniqueId();
      }
      return id;
    }
  
  }
  </code></pre>
  
  <p>The problem is that if I need that id somewhere in my javascript code in the component, I need to retrieve it again.  So I thought I could do the following:</p>
  
  <pre><code>&lt;ui:composition ...&gt;
    &lt;c:set var="id" value="#{jsfSupport.generateId(id)}" /&gt;
    &lt;div class="myComponent" id="#{id}"&gt;
       ...
    &lt;/div&gt;
    &lt;script type="text/javascript"&gt;
      document.getElementById('#{id}');
    &lt;/script&gt;
  &lt;/ui:composition&gt;
  </code></pre>
  
  <p>But that doesn't work.  The id gets regenerated anyway and I get two different ones.
  Any ideas on what would be the ideal way to do this?</p>