I'm using Primefaces. For some pages I want to exclude the resources which are included by primefacs, especially the theme resource.
<link type="text/css" rel="stylesheet" href="/context/javax.faces.resource/theme.css?ln=primefaces-owntheme" />
I try that with a SystemEventListener as following:
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<String, Object> attrs = resource.getAttributes();
String resourceLibrary = (String) attrs.get("library");
String resourceName = (String) attrs.get("name");
if ("primefaces-owntheme".equals(resourceLibrary) && "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);
}
}
and in the faces-config.xml
<application>
<system-event-listener>
<system-event-listener-class>
com.mycompany.mavenproject1.PrimeFacesResourceRemover
</system-event-listener-class>
<system-event-class>
javax.faces.event.PostAddToViewEvent
</system-event-class>
</system-event-listener>
</application>
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?