MyFaces Core
  1. MyFaces Core
  2. MYFACES-3116

MyFaces cannot resolve @ManagedProperty on startup, throws UnsupportedOperationException

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 2.0.5
    • Fix Version/s: 2.0.6
    • Component/s: None
    • Labels:
      None
    • Environment:
      Tomcat 6

      Description

      I have a managedbean which initializes some services:
      @ManagedBean(eager = true)
      @ApplicationScoped
      public class Services {
      private SecurityContext securityContext;
      @PostConstruct
      public void init()

      { securityContext = new SecurityContext(); }

      }

      In another bean i want to inject a ManagedProperty of type SecurityContext (applicationscoped as well)
      @ManagedBean(eager = true)
      @ApplicationScoped
      public class Validator{
      @ManagedProperty("#

      {services.securityContext}

      ")
      private SecurityContext securityContext;
      //irrelevant code ...
      public void setSecurityContext(SecurityContext securityContext)

      { this.securityContext = securityContext; }

      }

      This is working with latest version of the reference implementation (mojarra 2.1.0). I was trying to use MyFaces because mojarra has another ugly bug, which initilizes application scoped beans twice.

      On application startup myfaces cannot init Validator due to this exception:

      INFO: Creating instance of com.eskupina.webrepositoryinterface.Services
      26.04.2011 12:20:14 org.apache.myfaces.config.annotation.TomcatAnnotationLifecycleProvider newInstance
      INFO: Creating instance of com.eskupina.webrepositoryinterface.Validator
      26.04.2011 12:20:14 org.apache.myfaces.webapp.AbstractFacesInitializer initFaces
      SCHWERWIEGEND: An error occured while initializing MyFaces: This method is not supported during startup
      java.lang.UnsupportedOperationException: This method is not supported during startup
      at org.apache.myfaces.context.servlet.StartupServletExternalContextImpl.getRequestMap(StartupServletExternalContextImpl.java:149)
      at org.apache.myfaces.config.ManagedBeanBuilder.getScope(ManagedBeanBuilder.java:540)
      at org.apache.myfaces.config.ManagedBeanBuilder.getNarrowestScope(ManagedBeanBuilder.java:462)
      at org.apache.myfaces.config.ManagedBeanBuilder.isInValidScope(ManagedBeanBuilder.java:433)
      at org.apache.myfaces.config.ManagedBeanBuilder.initializeProperties(ManagedBeanBuilder.java:322)
      at org.apache.myfaces.config.ManagedBeanBuilder.buildManagedBean(ManagedBeanBuilder.java:169)
      at org.apache.myfaces.webapp.AbstractFacesInitializer._createEagerBeans(AbstractFacesInitializer.java:221)
      at org.apache.myfaces.webapp.AbstractFacesInitializer.initFaces(AbstractFacesInitializer.java:138)
      at org.apache.myfaces.webapp.StartupServletContextListener.contextInitialized(StartupServletContextListener.java:111)
      at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4135)
      at org.apache.catalina.core.StandardContext.start(StandardContext.java:4630)
      at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:791)
      at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:771)
      at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:546)
      at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:905)
      at org.apache.catalina.startup.HostConfig.deployWARs(HostConfig.java:740)
      at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:500)
      at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1277)
      at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:321)
      at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
      at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053)
      at org.apache.catalina.core.StandardHost.start(StandardHost.java:785)
      at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
      at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:445)
      at org.apache.catalina.core.StandardService.start(StandardService.java:519)
      at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
      at org.apache.catalina.startup.Catalina.start(Catalina.java:581)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      at java.lang.reflect.Method.invoke(Method.java:597)
      at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)
      at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)
      26.04.2011 12:20:14 org.apache.catalina.core.StandardContext start
      SCHWERWIEGEND: Error filterStart
      26.04.2011 12:20:14 org.apache.catalina.core.StandardContext start

        Activity

        Hide
        Jakob Korherr added a comment -

        The solution was to check if MyFaces is currently starting (StartupServletExternalContextImpl is used) and to avoid calls to getRequestMap() and getSessionMap() in that case. In addition, the FacesContext attribute map had to be used instead of the request map for "global" values (e.g. needed in cyclic reference detection).

        Also, an eager bean must not be initialized if it has already been initialized by another eager beans via a @ManagedProperty reference. Otherwise it would be created twice!

        Show
        Jakob Korherr added a comment - The solution was to check if MyFaces is currently starting (StartupServletExternalContextImpl is used) and to avoid calls to getRequestMap() and getSessionMap() in that case. In addition, the FacesContext attribute map had to be used instead of the request map for "global" values (e.g. needed in cyclic reference detection). Also, an eager bean must not be initialized if it has already been initialized by another eager beans via a @ManagedProperty reference. Otherwise it would be created twice!
        Hide
        Alois Glomann added a comment -

        Tested with 2.1.0-SNAPSHOT. Works for me. Thx for your quick help

        Show
        Alois Glomann added a comment - Tested with 2.1.0-SNAPSHOT. Works for me. Thx for your quick help
        Hide
        Jakob Korherr added a comment -

        Great, you're welcome!

        Show
        Jakob Korherr added a comment - Great, you're welcome!

          People

          • Assignee:
            Jakob Korherr
            Reporter:
            Alois Glomann
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development