Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jsf-2/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在JSF中以编程方式获取资源映射?_Jsf_Jsf 2_Resources - Fatal编程技术网

如何在JSF中以编程方式获取资源映射?

如何在JSF中以编程方式获取资源映射?,jsf,jsf-2,resources,Jsf,Jsf 2,Resources,我想访问资源图,而不是像中那样从我的CCS文件访问 background-image: url("#{resource['primefaces-supertheme:images/ui-icons_ffffff_0.png']}"); 但是从我的豆子。仅使用EL评估是否可行?真正的Java变体是,然后: 请注意,您可以通过编程方式计算EL。你可以用这个 FacesContext context = FacesContext.getCurrentInstance(); String url =

我想访问资源图,而不是像中那样从我的CCS文件访问

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

但是从我的豆子。仅使用EL评估是否可行?

真正的Java变体是,然后:

请注意,您可以通过编程方式计算EL。你可以用这个

FacesContext context = FacesContext.getCurrentInstance();
String url = context.getApplication().evaluateExpressionGet(context, "#{resource['primefaces-supertheme:images/ui-icons_ffffff_0.png']}", String.class);
// ...
如果您碰巧使用JSF实用程序库OmniFaces,可以通过实用程序类将其简化为:

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

谢谢你的回答!所有变体都很有用。最简单的是全方位的。顺便说一句,我使用Omnifaces。Java变体很酷:-)
String url = Faces.evaluateExpressionGet("#{resource['primefaces-supertheme:images/ui-icons_ffffff_0.png']}");
// ...