JSF2: How are the *.taglib.xml files discovered in jsf-impl.jar?

泪湿孤枕 提交于 2021-02-07 09:17:57

问题


In jsf-impl.jar (which can be found on mvnrepository.com), the *.taglib.xml files are located in directory com/sun/faces/metadata/taglib/.

I don't understand how they're discovered in this case, because chapter 10.3.2 of the JSF 2 specification says:

10.3.2 Facelet Tag Library mechanism

...

The run time must support two modes of discovery for Facelet tag library descriptors

  • Via declaration in the web.xml, as specified in Section 11.1.3 “Application Configuration Parameters”

  • Via auto discovery by placing the tag library descriptor file within a jar on the web application classpath, naming the file so that it ends with “.taglib.xml”, without the quotes, and placing the file in the META-INF directory in the jar file.

...

Here, they're not located in directory META-INF, so how does it work?

Note: in META-INF, they are some .tld files, but I'm not interested in them since I'm not using JSP as the view, but Facelets.


回答1:


It isn't using the taglib.xml for that. It's programmatically registering them via com.sun.faces.facelets.tag.jsf.html.HtmlLibrary in com.sun.faces.application.ApplicationAssociate which is executed during startup. Here are the relevant lines from Mojarra 2.2.1 (copypasted from Grepcode):

954        c.addTagLibrary(new CoreLibrary());
955        c.addTagLibrary(new CoreLibrary(CoreLibrary.XMLNSNamespace));
956        c.addTagLibrary(new HtmlLibrary());
957        c.addTagLibrary(new HtmlLibrary(HtmlLibrary.XMLNSNamespace));
958        c.addTagLibrary(new UILibrary());
959        c.addTagLibrary(new UILibrary(UILibrary.XMLNSNamespace));
960        c.addTagLibrary(new JstlCoreLibrary());
961        c.addTagLibrary(new JstlCoreLibrary(JstlCoreLibrary.IncorrectNamespace));
962        c.addTagLibrary(new JstlCoreLibrary(JstlCoreLibrary.XMLNSNamespace));
963        c.addTagLibrary(new PassThroughAttributeLibrary());
964        c.addTagLibrary(new PassThroughElementLibrary());
965        c.addTagLibrary(new FunctionLibrary(JstlFunction.class, FunctionLibrary.Namespace));
966        c.addTagLibrary(new FunctionLibrary(JstlFunction.class, FunctionLibrary.XMLNSNamespace));
967        if (isDevModeEnabled()) {
968            c.addTagLibrary(new FunctionLibrary(DevTools.class, DevTools.Namespace));
969            c.addTagLibrary(new FunctionLibrary(DevTools.class, DevTools.NewNamespace));
970        }
971        c.addTagLibrary(new CompositeLibrary());
972        c.addTagLibrary(new CompositeLibrary(CompositeLibrary.XMLNSNamespace));


来源:https://stackoverflow.com/questions/19027595/jsf2-how-are-the-taglib-xml-files-discovered-in-jsf-impl-jar

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!