I am using Primefaces. For some pages, I want to exclude resources that are part of the pre-facts, especially the theme resource.
<link type="text/css" rel="stylesheet" href="/context/javax.faces.resource/theme.css?ln=primefaces-owntheme" />
I am trying to do this using SystemEventListener as follows:
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)) {
context.getViewRoot().removeComponentResource(context, resource, HEAD);
}
}
}
@Override
public boolean isListenerForSource(Object source) {
return (source instanceof UIViewRoot);
}
}
and in 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 enable resouce on the page manually, but they do not work with the resources that are part of Primefaces. How to remove these resources?
source
share