我想访问资源地图,而不是像在我的CCS文件中那样
background-image: url("#{resource['primefaces-supertheme:images/ui-icons_ffffff_0.png']}");
但是从我的角度来看,仅使用EL表达式评估是否可能?
真正的Java版本应该是Application#createResrouce()
,然后再使用Resource#getRequestPath()
方法:
FacesContext context = FacesContext.getCurrentInstance();
Resource resource = context.getApplication().getResourceHandler().createResource("images/ui-icons_ffffff_0.png", "primefaces-supertheme");
String url = resource.getRequestPath();
// ...
Application#evaluateExpressionGet()
方法来实现此功能。FacesContext context = FacesContext.getCurrentInstance();
String url = context.getApplication().evaluateExpressionGet(context, "#{resource['primefaces-supertheme:images/ui-icons_ffffff_0.png']}", String.class);
// ...
Faces
实用程序类来简化此过程:String url = Faces.evaluateExpressionGet("#{resource['primefaces-supertheme:images/ui-icons_ffffff_0.png']}");
// ...