[英]Two JSF libraries providing the same renderer
Short Version : 简短版本 :
If two JSF library jar files both include a custom renderer for the same family and type, is there any way from within the library itself (ie not from the containing app) of specifying which one should be used? 如果两个JSF库jar文件都包含针对同一家族和类型的自定义渲染器,那么从库本身内部(即不是从包含的应用程序中)是否有任何方法指定应使用哪个? Something like assigning a priority, with higher ones used in preference to lower ones?
诸如分配优先级,优先级较高的优先级较低的优先级?
Longer Version : 较长版本 :
I'm using Primefaces in a project and trying to override the provided head renderer with my own: 我在项目中使用Primefaces,并尝试使用我自己的头渲染器覆盖提供的头渲染器:
<render-kit>
<renderer>
<component-family>javax.faces.Output</component-family>
<renderer-type>javax.faces.Head</renderer-type>
<renderer-class>com.example.MyHeadRenderer</renderer-class>
</renderer>
</render-kit>
If I put that into the WEB-INF/faces-config.xml
of the war file then it's all good, and my renderer gets used. 如果将其放入war文件的
WEB-INF/faces-config.xml
中,那么一切都很好,并且渲染器也被使用了。
However, if I try to deploy my code as part of a library jar (my-utils.jar), with the renderer defined in META-INF/faces-config.xml
, then the Primefaces one is used. 但是,如果我尝试将代码部署为库jar(my-utils.jar)的一部分,并使用
META-INF/faces-config.xml
定义的渲染器,则将使用Primefaces。 This contains exactly the same definition, so I'm guessing it just depends on the order they get loaded. 它包含完全相同的定义,所以我猜它仅取决于它们加载的顺序。 Indeed, renaming my library to "xx-comps.jar" works, so it would appear that JSF is loading
faces-config.xml
files from all jar files in alphabetical order, with later entries just overwriting earlier ones. 确实,将我的库重命名为“ xx-comps.jar”是可行的,因此看来JSF是以字母顺序从所有jar文件中加载
faces-config.xml
文件的,后来的条目只是覆盖了以前的条目。
Is there any way of forcing the selection to my library? 有什么方法可以强制选择我的书架吗?
So far, I have these options: 到目前为止,我有以下选择:
WEB-INF/faces-config.xml
of the war. WEB-INF/faces-config.xml
中。 WEB-INF/faces-config.xml
. WEB-INF/faces-config.xml
引用它。 The first three all work but are not ideal, as (1) and (2) require changes outside my library, and (3) just looks dodgy as hell.... 前三个都可以工作,但并不理想,因为(1)和(2)要求在我的库外进行更改,并且(3)看起来很狡猾。
The fourth is just an idea as I've never written a render kit before so not aware of the effort involved. 第四个只是一个想法,因为我之前从未编写过渲染工具包,因此不知道所涉及的工作。 No idea if it is practical or would work, but it is better than (1) because at least the application only references a single render kit, and does not need to be updated if/when new renderers are added.
不知道它是否可行或可行,但是它比(1)更好,因为至少该应用程序仅引用单个渲染工具,并且在/当添加新渲染器时不需要更新。 Happy to put more effort into researching this approach if it seems a reasonable solution.
如果这是一个合理的解决方案,很乐意花更多的精力研究这种方法。
Also, I'd ideally prefer to use annotations rather than XML: 另外,理想情况下,我更喜欢使用注释而不是XML:
@FacesRenderer(componentFamily = "javax.faces.Output", rendererType = "javax.faces.Head")
public class MyHeadRenderer extends Renderer {
...
}
Thanks 谢谢
You can specify the ordering via <ordering>
in faces-config.xml
of the JAR. 您可以通过JAR的
faces-config.xml
中的<ordering>
指定排序。
Eg if you want your utility library to be loaded after all others, then just do so: 例如,如果您希望在所有其他应用程序之后都加载实用程序库,则只需这样做:
<ordering>
<after>
<others />
</after>
</ordering>
If you want to force an explicit ordering, then hook on specifically PrimeFaces, which has a <name>primefaces</name>
in its faces-config.xml
: 如果要强制执行显式排序,请专门连接PrimeFaces,其
faces-config.xml
具有<name>primefaces</name>
:
<ordering>
<after>
<name>primefaces</name>
</after>
</ordering>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.