public static void addComponentResource(FacesContext context, String name, String library) { addComponentResource(context, name, library, "head"); }
protected String getResourceRequestPath(FacesContext context, String resourceName) { return ResourceUtils.getResourceRequestPath(context, resourceName); }
protected String getResourceURL(FacesContext context, String value) { return ResourceUtils.getResourceURL(context, value); }
&& !requestContext.getApplicationContext().getConfig().isAtLeastJSF23()) { ArrayList<ResourceUtils.ResourceInfo> initialResources = DynamicResourcesPhaseListener.getInitialResources(context); ArrayList<ResourceUtils.ResourceInfo> currentResources = ResourceUtils.getComponentResources(context); if (initialResources != null && currentResources != null && currentResources.size() > initialResources.size()) { startEval(); ArrayList<String> stylesheets = ResourceUtils.filterStylesheets(context, newResources); if (stylesheets != null && !stylesheets.isEmpty()) { String script = "PrimeFaces.ajax.Utils.loadStylesheets(['" + CollectionUtils.join(stylesheets, "','") + "']);"; ArrayList<String> scripts = ResourceUtils.filterScripts(context, newResources); if (scripts != null && !scripts.isEmpty()) { String script = "PrimeFaces.ajax.Utils.loadScripts(['" + CollectionUtils.join(scripts, "','") + "']);";
public static ArrayList<String> filterStylesheets(FacesContext context, ArrayList<ResourceInfo> resourceInfos) { if (resourceInfos == null || resourceInfos.isEmpty()) { return null; } ResourceHandler resourceHandler = context.getApplication().getResourceHandler(); ArrayList<String> stylesheets = new ArrayList<String>(); for (ResourceInfo resourceInfo : resourceInfos) { if (isStylesheet(resourceInfo.getResource()) && !isInline(resourceInfo)) { Resource resource; if (ComponentUtils.isValueBlank(resourceInfo.getLibrary())) { resource = resourceHandler.createResource(resourceInfo.getName()); } else { resource = resourceHandler.createResource(resourceInfo.getName(), resourceInfo.getLibrary()); } if (resource == null) { LOG.log(Level.WARNING, "Resource not found, ignore it. Name: " + resourceInfo.getName() + ", Library: " + resourceInfo.getLibrary()); } else { stylesheets.add(resource.getRequestPath()); } } } return stylesheets; }
public static ArrayList<String> filterScripts(FacesContext context, ArrayList<ResourceInfo> resourceInfos) { if (resourceInfos == null || resourceInfos.isEmpty()) { return null; } ResourceHandler resourceHandler = context.getApplication().getResourceHandler(); ArrayList<String> scripts = new ArrayList<String>(); for (ResourceInfo resourceInfo : resourceInfos) { if (isScript(resourceInfo.getResource()) && !isInline(resourceInfo)) { Resource resource; if (ComponentUtils.isValueBlank(resourceInfo.getLibrary())) { resource = resourceHandler.createResource(resourceInfo.getName()); } else { resource = resourceHandler.createResource(resourceInfo.getName(), resourceInfo.getLibrary()); } if (resource == null) { LOG.log(Level.WARNING, "Resource not found, ignore it. Name: " + resourceInfo.getName() + ", Library: " + resourceInfo.getLibrary()); } else { scripts.add(resource.getRequestPath()); } } } return scripts; }
&& !applicationContext.getEnvironment().isAtLeastJsf23()) { List<ResourceUtils.ResourceInfo> initialResources = DynamicResourcesPhaseListener.getInitialResources(context); List<ResourceUtils.ResourceInfo> currentResources = ResourceUtils.getComponentResources(context); if (initialResources != null && currentResources != null && currentResources.size() > initialResources.size()) {
public static List<ResourceInfo> getComponentResources(FacesContext context) { List<ResourceInfo> resourceInfos = new ArrayList<>(); List<UIComponent> resources = context.getViewRoot().getComponentResources(context, "head"); if (resources != null) { for (int i = 0; i < resources.size(); i++) { UIComponent resource = resources.get(i); ResourceUtils.ResourceInfo resourceInfo = newResourceInfo(resource); if (resourceInfo != null && !resourceInfos.contains(resourceInfo)) { resourceInfos.add(resourceInfo); } } } return resourceInfos; }
@Override public void afterPhase(PhaseEvent event) { FacesContext context = event.getFacesContext(); // we only need to collect resources on ajax requests // for non ajax, the head will always be rendered again if (context.getViewRoot() == null || !context.getPartialViewContext().isAjaxRequest()) { return; } // we can also skip non-postback ajax requests, which occurs e.g. without a form if (!context.isPostback()) { return; } // skip update=@all as the head, with all resources, will already be rendered if (context.getPartialViewContext().isRenderAll()) { return; } // JSF 2.3 contains a own dynamic resource handling if (PrimeApplicationContext.getCurrentInstance(context).getEnvironment().isAtLeastJsf23()) { return; } // collect all current resources before new components can be added to the view in later phases List<ResourceUtils.ResourceInfo> initialResources = ResourceUtils.getComponentResources(context); putInitialResources(context, initialResources); }
public static ArrayList<ResourceInfo> getComponentResources(FacesContext context) { ArrayList<ResourceInfo> resourceInfos = new ArrayList<ResourceInfo>(); List<UIComponent> resources = context.getViewRoot().getComponentResources(context, "head"); if (resources != null) { for (UIComponent resource : resources) { ResourceUtils.ResourceInfo resourceInfo = newResourceInfo(resource); if (resourceInfo != null && !resourceInfos.contains(resourceInfo)) { resourceInfos.add(resourceInfo); } } } return resourceInfos; }
public static void addComponentResource(FacesContext context, String name) { addComponentResource(context, name, Constants.LIBRARY, "head"); }
@Override public void afterPhase(PhaseEvent event) { FacesContext context = event.getFacesContext(); // we only need to collect resources on ajax requests // for non ajax, the head will always be rendered again if (context.getViewRoot() == null || !context.getPartialViewContext().isAjaxRequest()) { return; } // we can also skip non-postback ajax requests, which occurs e.g. without a form if (!context.isPostback()) { return; } // skip update=@all as the head will all resources will already be rendered if (context.getPartialViewContext().isRenderAll()) { return; } // JSF 2.3 contains a own dynamic resource handling if (RequestContext.getCurrentInstance(context).getApplicationContext().getConfig().isAtLeastJSF23()) { return; } // collect all current resources before new components can be added to the view in later phases ArrayList<ResourceUtils.ResourceInfo> initialResources = ResourceUtils.getComponentResources(context); putInitialResources(context, initialResources); }
src = ResourceUtils.getResourceURL(context, (String) value);
public static void addComponentResource(FacesContext context, String name, String library) { addComponentResource(context, name, library, "head"); }
public static void addComponentResource(FacesContext context, String name) { addComponentResource(context, name, Constants.LIBRARY, "head"); }
public void processEvent(SystemEvent event) throws AbortProcessingException { FacesContext context = FacesContext.getCurrentInstance(); UIViewRoot view = context.getViewRoot(); String renderKitId = view.getRenderKitId(); if (Constants.MOBILE_RENDER_KIT_ID.equals(renderKitId)) { ResourceUtils.addComponentResource(context, "mobile/widgets/datepicker.css", Constants.LIBRARY, "head"); ResourceUtils.addComponentResource(context, "mobile/widgets/datepicker.js", Constants.LIBRARY, "head"); } }