C'est une méthode pour ajouter dynamiquement des paramètres au moment de la construction pour obtenir les derniers Javascript et CSS chargés par JSF Facelets. Avant modification) vendor.js Après modification) vendor.js? V = 12345678
Au revoir à Super Reload.
Créez une classe qui hérite de la classe ResourceHandlerWrapper.
CustomResourceHandler.java
package com.sample;
import java.util.Arrays;
import javax.faces.application.Resource;
import javax.faces.application.ResourceHandler;
import javax.faces.application.ResourceHandlerWrapper;
import javax.faces.application.ResourceWrapper;
public class CustomResourceHandler extends ResourceHandlerWrapper {
private final ResourceHandler wrapped;
public CustomResourceHandler(ResourceHandler wrapped) {
this.wrapped = wrapped;
}
@Override
public Resource createResource(String resourceName) {
return createResource(resourceName, null, null);
}
@Override
public Resource createResource(String resourceName, String libraryName) {
return createResource(resourceName, libraryName, null);
}
@Override
public Resource createResource(String resourceName, String libraryName, String contentType) {
final Resource resource = super.createResource(resourceName, libraryName, contentType);
if (resource == null) {
return null;
}
if (!Arrays.asList("js", "css").contains(libraryName)) {
//Ciblé par Javascript et CSS
return resource;
}
return new ResourceWrapper() {
@Override
public String getRequestPath() {
return super.getRequestPath() + "&(Paramètres de requête arbitraires)";
}
@Override // Necessary because this is missing in ResourceWrapper (will be fixed in JSF 2.2).
public String getResourceName() {
return resource.getResourceName();
}
@Override // Necessary because this is missing in ResourceWrapper (will be fixed in JSF 2.2).
public String getLibraryName() {
return resource.getLibraryName();
}
@Override // Necessary because this is missing in ResourceWrapper (will be fixed in JSF 2.2).
public String getContentType() {
return resource.getContentType();
}
@Override
public Resource getWrapped() {
return resource;
}
};
}
@Override
public ResourceHandler getWrapped() {
return wrapped;
}
}
Enregistrez le gestionnaire créé ci-dessus dans faces-config.xml.
WEB-INF/faces-config.xml
<application>
<resource-handler>com.sample.CustomResourceHandler</resource-handler>
</application>
Recommended Posts