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 it possible with EL evaluation only?
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();
// ...
Note that you could just evaluate 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 happen to use JSF utility library OmniFaces, this can be simplified via Faces
utility class as:
String url = Faces.evaluateExpressionGet("#{resource['primefaces-supertheme:images/ui-icons_ffffff_0.png']}");
// ...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With