Esempio n. 1
0
 protected static Application getApplication() {
   FacesContext context = FacesContext.getCurrentInstance();
   if (context != null) {
     return (FacesContext.getCurrentInstance().getApplication());
   }
   ApplicationFactory afactory =
       (ApplicationFactory) FactoryFinder.getFactory(FactoryFinder.APPLICATION_FACTORY);
   return (afactory.getApplication());
 }
Esempio n. 2
0
  public void registerELResolverAndListenerWithJsp(ServletContext context, boolean reloaded) {

    if (webConfig.isSet(WebContextInitParameter.ExpressionFactory) || !isJspTwoOne(context)) {

      // first try to load a factory defined in web.xml
      if (!installExpressionFactory(
          context, webConfig.getOptionValue(WebContextInitParameter.ExpressionFactory))) {

        throw new ConfigurationException(
            MessageUtils.getExceptionMessageString(
                MessageUtils.INCORRECT_JSP_VERSION_ID,
                WebContextInitParameter.ExpressionFactory.getDefaultValue(),
                WebContextInitParameter.ExpressionFactory.getQualifiedName()));
      }

    } else {

      // JSP 2.1 specific check
      if (JspFactory.getDefaultFactory().getJspApplicationContext(context) == null) {
        return;
      }

      // register an empty resolver for now. It will be populated after the
      // first request is serviced.
      FacesCompositeELResolver compositeELResolverForJsp =
          new ChainTypeCompositeELResolver(FacesCompositeELResolver.ELResolverChainType.JSP);
      ApplicationAssociate associate = ApplicationAssociate.getInstance(context);
      if (associate != null) {
        associate.setFacesELResolverForJsp(compositeELResolverForJsp);
      }

      // get JspApplicationContext.
      JspApplicationContext jspAppContext =
          JspFactory.getDefaultFactory().getJspApplicationContext(context);

      // cache the ExpressionFactory instance in ApplicationAssociate
      if (associate != null) {
        associate.setExpressionFactory(jspAppContext.getExpressionFactory());
      }

      // register compositeELResolver with JSP
      try {
        jspAppContext.addELResolver(compositeELResolverForJsp);
      } catch (IllegalStateException e) {
        ApplicationFactory factory =
            (ApplicationFactory) FactoryFinder.getFactory(FactoryFinder.APPLICATION_FACTORY);
        Application app = factory.getApplication();
        if (app.getProjectStage() != ProjectStage.UnitTest && !reloaded) {
          throw e;
        }
      }

      // register JSF ELContextListenerImpl with Jsp
      ELContextListenerImpl elContextListener = new ELContextListenerImpl();
      jspAppContext.addELContextListener(elContextListener);
    }
  }
Esempio n. 3
0
 /** @see javax.faces.context.FacesContext#getApplication() */
 public Application getApplication() {
   assertNotReleased();
   if (null != application) {
     return application;
   }
   ApplicationFactory aFactory =
       (ApplicationFactory) FactoryFinder.getFactory(FactoryFinder.APPLICATION_FACTORY);
   application = aFactory.getApplication();
   assert (null != application);
   return application;
 }
Esempio n. 4
0
  public Application getApplication() {
    checkReleased();

    if (application == null) {
      ApplicationFactory aFactory =
          (ApplicationFactory) FactoryFinder.getFactory(FactoryFinder.APPLICATION_FACTORY);
      this.application = aFactory.getApplication();
    }

    return this.application;
  }
Esempio n. 5
0
 //
 // Methods from TestCase
 //
 public void setUp() {
   super.setUp();
   ApplicationFactory aFactory =
       (ApplicationFactory) FactoryFinder.getFactory(FactoryFinder.APPLICATION_FACTORY);
   application = aFactory.getApplication();
   UIViewRoot viewRoot =
       Util.getViewHandler(getFacesContext()).createView(getFacesContext(), null);
   viewRoot.setViewId("viewId");
   viewRoot.setLocale(Locale.US);
   getFacesContext().setViewRoot(viewRoot);
 }
Esempio n. 6
0
  private static ELResolver _getELResolver(FacesContext context) {
    // First try the FacesContext, which is a faster way to
    // get the ELResolver (and the 99.9% scenario)
    if (context != null) return context.getApplication().getELResolver();

    // If that fails, then we're likely outside of the JSF lifecycle.
    // Look to the ApplicationFactory.
    ApplicationFactory factory =
        (ApplicationFactory) FactoryFinder.getFactory(FactoryFinder.APPLICATION_FACTORY);
    return factory.getApplication().getELResolver();
  }
 protected void initializeJSF() {
   // Make sure the faces application is set:
   {
     ApplicationFactory f =
         (ApplicationFactory) FactoryFinder.getFactory(FactoryFinder.APPLICATION_FACTORY);
     Application a = f.getApplication();
     if (!(a instanceof SystemApplication)) {
       Application b = new SystemApplication(a);
       f.setApplication(b);
     }
   }
 }
  /**
   * This test verifies that if the variable resolver does not find a managed bean it tries to
   * instantiate it if it was added to the application's managed bean factory list.
   */
  public void testManagedBean() throws Exception {
    String beanName = "com.sun.faces.TestBean";

    ManagedBeanInfo beanInfo =
        new ManagedBeanInfo(beanName, beanName, "session", null, null, null, null);

    ApplicationFactory aFactory =
        (ApplicationFactory) FactoryFinder.getFactory(FactoryFinder.APPLICATION_FACTORY);
    ApplicationImpl application = (ApplicationImpl) aFactory.getApplication();
    ApplicationAssociate associate = ApplicationAssociate.getCurrentInstance();
    BeanManager manager = associate.getBeanManager();
    manager.register(beanInfo);

    VariableResolver variableResolver = application.getVariableResolver();

    Object result = variableResolver.resolveVariable(getFacesContext(), beanName);

    assertTrue(result instanceof TestBean);
  }
Esempio n. 9
0
 /**
  * This constructor uses the current <code>Application</code> instance to obtain the navigation
  * mappings used to make navigational decisions.
  */
 public NavigationHandlerImpl() {
   super();
   if (logger.isLoggable(Level.FINE)) {
     logger.log(Level.FINE, "Created NavigationHandler instance ");
   }
   // if the user is using the decorator pattern, this would cause
   // our ApplicationAssociate to be created, if it isn't already
   // created.
   ApplicationFactory aFactory =
       (ApplicationFactory) FactoryFinder.getFactory(FactoryFinder.APPLICATION_FACTORY);
   aFactory.getApplication();
   ApplicationAssociate associate =
       ApplicationAssociate.getInstance(FacesContext.getCurrentInstance().getExternalContext());
   if (associate != null) {
     caseListMap = associate.getNavigationCaseListMappings();
     wildCardSet = associate.getNavigationWildCardList();
     navigationConfigured = (wildCardSet != null && caseListMap != null);
     development = associate.isDevModeEnabled();
   }
 }
Esempio n. 10
0
 private static Application getApplication() {
   ApplicationFactory appFactory =
       (ApplicationFactory) FactoryFinder.getFactory(FactoryFinder.APPLICATION_FACTORY);
   return appFactory.getApplication();
 }
  /** @return return the Application instance for this context. */
  protected Application getApplication() {

    ApplicationFactory afactory =
        (ApplicationFactory) FactoryFinder.getFactory(FactoryFinder.APPLICATION_FACTORY);
    return afactory.getApplication();
  }
Esempio n. 12
0
 public void setUp() {
   super.setUp();
   ApplicationFactory aFactory =
       (ApplicationFactory) FactoryFinder.getFactory(FactoryFinder.APPLICATION_FACTORY);
   application = (ApplicationImpl) aFactory.getApplication();
 }