How to get a soft resource map in JSF?

I want to access the resource map, not from my CCS file, as in

background-image: url("#{resource['primefaces-supertheme:images/ui-icons_ffffff_0.png']}"); 

but from my bean. Is this possible only when evaluating EL?

+4
source share
1 answer

The true Java variant would be Application#createResrouce() and then Resource#getRequestPath() :

 FacesContext context = FacesContext.getCurrentInstance(); Resource resource = context.getApplication().getResourceHandler().createResource("images/ui-icons_ffffff_0.png", "primefaces-supertheme"); String url = resource.getRequestPath(); // ... 

Please note that you can simply calculate EL programmatically. You can use Application#evaluateExpressionGet() for this.

 FacesContext context = FacesContext.getCurrentInstance(); String url = context.getApplication().evaluateExpressionGet(context, "#{resource['primefaces-supertheme:images/ui-icons_ffffff_0.png']}", String.class); // ... 

If you use the JSF OmniFaces utility library, this can be simplified with Faces as:

 String url = Faces.evaluateExpressionGet("#{resource['primefaces-supertheme:images/ui-icons_ffffff_0.png']}"); // ... 
+6
source

All Articles