如何从Facelets和web.xml引用JAR中的Facelets taglib? [英] How to reference Facelets taglib in JAR from Facelets and web.xml?

查看:133
本文介绍了如何从Facelets和web.xml引用JAR中的Facelets taglib?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Apache MyFaces Commons Validator TagLib.

如何将其添加到我的web.xml中? Commons JAR是通过Maven下载并解决的.

XHTML(我认为这是正确的):

<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:p="http://primefaces.prime.com.tr/ui"
      **xmlns:mcv="http://myfaces.apache.org/commons/validators"**>

web.xml:

<context-param>
  <!-- To add additional tab libs -->
  <param-name>facelets.LIBRARIES</param-name>
  <param-value>??.xml</param-value>
</context-param>

编辑:之所以要执行此步骤,是因为我尝试错误地引用了Maven依赖项,并且这样做了,我尝试从Apache上下载jar并从中托管它我自己的存储库管理器.我自己尝试托管的jar不包含taglib jar.

正确获得依赖关系后,一切正常运行,无需将balusC所推荐的taglib明确定义.谢谢!

<dependency>
    <groupId>org.apache.myfaces.commons</groupId>
    <artifactId>myfaces-commons</artifactId>
    <version>1.1.2</version>
</dependency>

解决方案

该库的*.taglib.xml文件已经在JAR的/META-INF中.您无需向web.xml添加任何内容.如果JAR位于webapp的运行时类路径中,则标记库将被自动发现.另请参见 JSF 2规范的第10.3.2章:

10.3.2 Facelet标签库机制

...

运行时必须支持Facelet标记库描述符的两种发现模式

    如第11.1.3节应用程序配置参数"中所述,
  • 在web.xml中的通过声明

  • 通过将标记库描述符文件放置在Web应用程序类路径上的jar中,通过命名文件使其以.taglib.xml结尾(不带引号)并将文件放置在中,从而实现自动发现目录中 jar文件.

...

因此,您只需确定JAR确实位于Web应用程序的运行时类路径中-通常为/WEB-INF/lib文件夹.

如果您在使用该库时遇到问题,那是由您未想到的其他原因引起的.

I am using the Apache MyFaces Commons Validator TagLib.

How should i add this to my web.xml? The commons JAR is downloaded and resolved through Maven.

XHTML (I think this is correct):

<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:p="http://primefaces.prime.com.tr/ui"
      **xmlns:mcv="http://myfaces.apache.org/commons/validators"**>

web.xml:

<context-param>
  <!-- To add additional tab libs -->
  <param-name>facelets.LIBRARIES</param-name>
  <param-value>??.xml</param-value>
</context-param>

EDIT: The reason why i got to this step is because that i have tried to referenced the Maven dependency incorrectly, and in doing so, i tried to download the jar off Apache and hosted it from my own repository manager. The jar i tried to host on my own did not contain the taglib jar.

After getting the dependency correctly, everything works as per normal, there was no need to explicitly define the taglib as what balusC commended. Thankx!

<dependency>
    <groupId>org.apache.myfaces.commons</groupId>
    <artifactId>myfaces-commons</artifactId>
    <version>1.1.2</version>
</dependency>

解决方案

The *.taglib.xml file of that library is already in /META-INF of the JAR. You don't need to add anything to your web.xml. If the JAR is in webapp's runtime classpath, the taglibs will be auto-discovered. See also chapter 10.3.2 of the JSF 2 specification:

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 discriptor 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.

...

So all you need to make sure is that the JAR is indeed in the webapp's runtime classpath -which is usually the /WEB-INF/lib folder.

If you're having a problem with using that library, it's caused by something else than you think.

这篇关于如何从Facelets和web.xml引用JAR中的Facelets taglib?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆