JSF2如何在web.xml文件中指定多个自定义元素库

时间:2013-08-27 08:31:23

标签: java xml jsf-2 config

我有两个自定义组件,我需要在同一个项目中使用它们。 我知道如何指定单个组件(tutorial:http://myjavabuddy.blogspot.com/2013/04/writing-custom-components-for-jsf-20.html)(web.xml):

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
  xmlns="http://java.sun.com/xml/ns/javaee"
  xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
  xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
  http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5">

<context-param>
    <param-name>javax.faces.FACELETS_LIBRARIES</param-name>
    <param-value>/WEB-INF/marquee-taglib.xml</param-value>
</context-param>
</web-app>

只要我添加另一个组件(web.xml),第一个元素就会停止工作:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
  xmlns="http://java.sun.com/xml/ns/javaee"
  xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
  xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
  http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5">

<context-param>
    <param-name>javax.faces.FACELETS_LIBRARIES</param-name>
    <param-value>/WEB-INF/marquee-taglib.xml</param-value>
</context-param>

<context-param>
    <param-name>javax.faces.FACELETS_LIBRARIES</param-name>
    <param-value>/WEB-INF/spinner-taglib.xml</param-value>
</context-param>
</web-app>

也不起作用:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
  xmlns="http://java.sun.com/xml/ns/javaee"
  xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
  xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
  http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5">

<context-param>
    <param-name>javax.faces.FACELETS_LIBRARIES</param-name>
    <param-value>/WEB-INF/marquee-taglib.xml</param-value>
    <param-value>/WEB-INF/spinner-taglib.xml</param-value>
</context-param>
</web-app>

如何在同一个web.xml文件中指定两个自定义元素?

1 个答案:

答案 0 :(得分:15)

使用以下内容:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
  xmlns="http://java.sun.com/xml/ns/javaee"
  xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
  xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
  http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5">

    <context-param>
        <param-name>javax.faces.FACELETS_LIBRARIES</param-name>
        <param-value>/WEB-INF/marquee-taglib.xml;/WEB-INF/spinner-taglib.xml</param-value>
    </context-param>
</web-app>

如果您使用myFaces,您可以查看here配置参数所期望的参数值。