Selectively disable JSF resource dependencies

时间:2015-07-28 17:14:21

标签: jsf resources bootsfaces butterfaces

If I use both bootsfaces and butterfaces in a single page, both libraries import their bundled jquery and bootstrap stylesheet as belows:

<link type="text/css" rel="stylesheet" href="/javax.faces.resource/bootstrap.min.css.xhtml?ln=butterfaces-configurable">
<link type="text/css" rel="stylesheet" href="/javax.faces.resource/css/bootstrap.min.css.xhtml?ln=bsf">

<script type="text/javascript" src="javax.faces.resource/jquery.min.js.xhtml?ln=butterfaces-configurable"></script>
<script type="text/javascript" src="javax.faces.resource/jquery.min.js.xhtml?ln=bsf"></script>

If both libraries use the same version , it waste bandwidth to import duplicate things. If both libraries use different versions , it is possible to have conflict. What is the best approach to deal with this? Can I selectively disable one component libraries to import certain stylesheets or scripts ?

2 个答案:

答案 0 :(得分:3)

您可以使用以下web.xml参数禁用在#ButterFaces中提供jQuery。

<context-param>
    <param-name>de.larmic.butterfaces.provideJQuery</param-name>
    <param-value>false</param-value>
</context-param>

如果你有自己的版本

,你也可以同样禁用bootstrap
<context-param>
    <param-name>de.larmic.butterfaces.provideBootstrap</param-name>
    <param-value>false</param-value>
</context-param>

答案 1 :(得分:1)

2016年1月22日更新:与此同时,我们(BootsFaces团队)竭尽全力为资源加载添加细粒度控制。有关详细信息,请参阅http://www.bootsfaces.net/layout/resourcemanagement.jsf。简而言之,如果检测到这些资源已经存在,BootsFaces不会加载jQuery,jQueryUI或Bootstrap。另外,您可以通过web.xml上下文参数停用资源加载。

过时的原始答案: 目前,唯一的解决方案是使用OmniFaces,就像BalusC所说的那样。我们可以提供改进BootsFaces,以便只有在JSF页面不提供这些库时才会添加jQuery.min.js和bootstrap.min.css。在这种情况下,ButterFaces将提供jQuery和BootsFaces。当然,您有责任确保提供的jQuery版本与BootsFaces兼容。