Uploaded image for project: 'Weld'
  1. Weld
  2. WELD-718

register Weld Servlet listener in web fragment

    XMLWordPrintable

Details

    • Feature Request
    • Status: Closed (View Workflow)
    • Minor
    • Resolution: Done
    • 1.1.0.Beta1
    • None
    • None
    • Documentation (Ref Guide, User Guide, etc.)
    • Low

    Description

      Instead of making the developer add the Weld Servle listener in their web.xml when using weld-servlet, might we consider registering it for them automatically but including it in a web.xml fragment or TLD that's bundled in weld-servlet.jar? The benefit of using the TLD is that it would work in pre-Servlet 3.0 environments.

      META-INF/web-fragment.xml
      <web-fragment xmlns="http://java.sun.com/xml/ns/javaee"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-fragment_3_0.xsd"
      version="3.0">
      <listener>
      <listener-class>org.jboss.weld.environment.servlet.Listener</listener-class>
      </listener>
      </web-fragment>

      META-INF/weld.tld
      <taglib xmlns="http://java.sun.com/xml/ns/javaee"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="
      http://java.sun.com/xml/ns/javaee
      http://java.sun.com/xml/ns/javaee/web-jsptaglibrary_2_0.xsd"
      version="2.0">
      <description>
      An empty tag library that registers a listener to bootstrap Weld in a Servlet container.
      </description>
      <tlib-version>1.0</tlib-version>
      <short-name>w</short-name>
      <uri>http://jboss.org/weld</uri>

      <!--
      This ServletContextListener initializes the runtime environment of the CDI
      Reference Implementation (Weld) when a web application including it is
      initialized by the container.
      -->
      <listener>
      <listener-class>org.jboss.weld.environment.servlet.Listener</listener-class>
      </listener>
      </taglib>

      Btw, we are already including other automatic configurations, such as a JSF phase listener and view handler (META-INF/faces-config.xml).

      If we require ordering, that leans more to web-fragment.xml as a solution, since it's possible to have ordering control. There is no guarantee as to when a listener will load that's defined in a TLD (the advantage is only for non-Servlet 3.0 containers). Given that Weld is a new programming model and likely to be used with newer containers, then I'd say we should go with web-fragment.xml.

      (Worse case scenario is we introduce a classifier for weld-servlet that will be for pre-Servlet 3.0 environments. Something like org.jboss.weld.servlet:weld-servlet:1.1:pre-servlet-3)

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              dan.j.allen Dan Allen (Inactive)
              Votes:
              1 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: