2 Replies Latest reply on Sep 17, 2013 7:40 AM by A J

    WeldApplicationFactory always returns own instance of Application

    A J Newbie



      I am using EAP 6.1. Deployed weld jar is: jboss-as-weld-7.2.0.Final-redhat-8.jar


      I wonder if implementation of the org.jboss.as.weld.webtier.jsf.WeldApplicationFactory is correct.


      The API of the javax.faces.application.ApplicationFactory states that setApplication method can be used to replace the Application object returned by the factory.

      But implementation of the WeldApplicationFactory does not allow this (replace Application object). Weld's getApplication method always returns the same object (Weld wrapped) in consecutive calls, ignoring setter calls.


      public class  WeldApplicationFactory extends ForwardingApplicationFactory {
      private volatile Application application;
      public Application  getApplication() {
           if (application == null) {
                synchronized (this) {
                     if (application == null) {
                          application = new WeldApplication(delegate().getApplication());
        return application;


      setter from WeldApplicationFactory parent class


      public void  setApplication(Application application) {


      I was trying to deploy Spring Web Flow/JSF application in the ear (without success). Spring's wrapped Application object is always replaced by the Weld.

      Spring wraps WeldApplication into its own object and sets it on the delegate (Weld). Weld sets it on its own delegate. But as you can see getter 'chain' is broken.

      I think it breaks 'pluggability' of JSF a bit.


      Is Weld implementation intended to work this way: Application object should not be wrapped or set by anyone?


      The possible workaround, which seems to work, is to create my custom ApplicationFactory and implement it the same way as you do (always reutrn my instance; do not call delegate in consecutive getter calls; I am wrapping WeldApplication into Spring as Spring does), but I am not sure if this is the best solution.