public String doLogout() {
   AlterableContext ctx = (AlterableContext) beanManager.getContext(SessionScoped.class);
   Bean<?> myBean = beanManager.getBeans(AccountBean.class).iterator().next();
   ctx.destroy(myBean);
   myBean = beanManager.getBeans(ShoppingCartBean.class).iterator().next();
   ctx.destroy(myBean);
   return "/main";
 }
Exemple #2
0
  /** Returns true if given scope is active in current context. */
  public static <S extends Annotation> boolean isScopeActive(Class<S> scope) {
    BeanManager beanManager = Util.getCdiBeanManager(FacesContext.getCurrentInstance());

    try {
      Context context = beanManager.getContext(scope);
      return context.isActive();
    } catch (ContextNotActiveException ignore) {
      return false;
    }
  }
 public String doLogoutAndRemoveCookie() {
   removeCookie();
   user.setUuid(null);
   em.merge(user);
   AlterableContext ctx = (AlterableContext) beanManager.getContext(SessionScoped.class);
   Bean<?> myBean = beanManager.getBeans(AccountBean.class).iterator().next();
   ctx.destroy(myBean);
   myBean = beanManager.getBeans(ShoppingCartBean.class).iterator().next();
   ctx.destroy(myBean);
   return "/main";
 }
  @AroundTimeout
  public Object invoke(final InvocationContext invocation) throws Exception {
    final ScopeContext<String> context =
        (ScopeContext<String>) beanManager.getContext(TimerScoped.class);

    final String key = getKey(invocation);
    final String previous = context.enter(key);
    try {
      return invocation.proceed();
    } finally {
      context.exit(previous);
    }
  }
Exemple #5
0
  /**
   * Returns concrete (non-proxied) bean instance of given class in current context.
   *
   * @param type the required bean type the instance must have
   * @param create whether to auto-create bean if not exist
   * @return a bean instance adhering to the required type
   */
  public static <T> T getBeanInstance(Class<T> type, boolean create) {
    BeanManager beanManager = Util.getCdiBeanManager(FacesContext.getCurrentInstance());
    @SuppressWarnings("unchecked")
    Bean<T> bean = (Bean<T>) beanManager.resolve(beanManager.getBeans(type));

    if (bean != null) {
      Context context = beanManager.getContext(bean.getScope());

      if (create) {
        return context.get(bean, beanManager.createCreationalContext(bean));
      } else {
        return context.get(bean);
      }
    } else {
      return null;
    }
  }
Exemple #6
0
 @Timeout
 public void timeout(Timer timer) {
   if (beanManager.getContext(ApplicationScoped.class).isActive()) {
     applicationScopeActive = true;
     if (beanId > 0.0) {
       if (beanId == simpleApplicationBeanInstance.get().getId()) {
         sameBean = true;
       }
     } else {
       beanId = simpleApplicationBeanInstance.get().getId();
     }
   }
   // CDITCK-221 - applicationScopeActive, beanId and sameBean have been set and are testable
   if (timer.getInfo().equals(CLIMB_COMMAND)) {
     climbed = true;
   }
   if (timer.getInfo().equals(DESCEND_COMMAND)) {
     descended = true;
   }
 }