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']}"); // ...
source share