title: Exclude resources in JSF
body: <p>I'm using Primefaces. For some pages I want to exclude the resources which are included by primefacs, especially the theme resource.</p>
  
  <pre><code>&lt;link type="text/css" rel="stylesheet" href="/context/javax.faces.resource/theme.css?ln=primefaces-owntheme" /&gt;    
  </code></pre>
  
  <p>I try that with a SystemEventListener as following:</p>
  
  <pre><code>public class PrimeFacesResourceRemover implements javax.faces.event.SystemEventListener {
  
  
    @Override
    public void processEvent(SystemEvent event) throws AbortProcessingException {
      FacesContext context = FacesContext.getCurrentInstance();
  
      UIViewRoot viewRoot = context.getViewRoot();
      for (UIComponent resource : viewRoot.getComponentResources(context, "head")) {
  
          Map&lt;String, Object&gt; attrs = resource.getAttributes();
          String resourceLibrary = (String) attrs.get("library");
          String resourceName = (String) attrs.get("name");
  
          if ("primefaces-owntheme".equals(resourceLibrary) &amp;&amp; "theme.css".equals(resourceName)) {
  
              // Remove resource from view
              context.getViewRoot().removeComponentResource(context, resource, HEAD);
          }
      }
    }
  
    /**
     * {@inheritDoc}
     */
    @Override
    public boolean isListenerForSource(Object source) {
      return (source instanceof UIViewRoot);
    }
  }
  </code></pre>
  
  <p>and in the faces-config.xml</p>
  
  <pre><code>    &lt;application&gt;
        &lt;system-event-listener&gt;
          &lt;system-event-listener-class&gt;
            com.mycompany.mavenproject1.PrimeFacesResourceRemover
          &lt;/system-event-listener-class&gt;
          &lt;system-event-class&gt;
            javax.faces.event.PostAddToViewEvent
          &lt;/system-event-class&gt;
        &lt;/system-event-listener&gt;
      &lt;/application&gt;
  </code></pre>
  
  <p>This works well, when I include a resouce on a page manually, but those not work with the resouces which are included by Primefaces. How can I remove those resouces?</p>