title: Adding Custom Attributes to Primefaces Autocomplete Component in JSF
body: <p>I asked about pass through attributes in a <a href="https://stackoverflow.com/questions/10484337/how-to-let-jsf-pass-through-html-attributes">different question</a> and found I could create a custom renderer for the <code>&lt;p:autocomplete&gt;</code> component but the problem is my custom renderer would be used for every p:autocomplete in my project (site-wide). Therefore I have elected to create a custom component which extends <code>org.primefaces.component.autocomplete.AutoComplete</code> and adds the necessary attributes to the text box.</p>
  
  <p>My initial thought was to add a constructor but it doesn't seem to work because the attribute map is null at this point:</p>
  
  <pre><code>@FacesComponent("com.mycomponents.SiteSearch")
  public class SiteSearch extends AutoComplete {
  
      public SiteSearch() {
          Map&lt;String,Object&gt; attrs = getAttributes();
          attrs.put("x-webkit-speech", null); 
          attrs.put("x-webkit-grammer", "builtin:search");
          attrs.put("onwebkitspeechchange", "this.form.submit();");
          attrs.put("placeholder", "Enter a Search Term");
      }   
  }
  </code></pre>
  
  <p>My other thought was leave this custom component empty (empty class) and then specify a custom renderer that extends <code>org.primefaces.component.autocomplete.AutoCompleteRenderer</code> and modify the attributes there.</p>
  
  <p>After all is said and done, I just need a way to keep these attributes separate to this one text box so just putting a custom renderer on the p:autoComplete is not going to work (unless maybe I can use renderType= attribute for this one p:autoComplete?).</p>