Example usage for org.springframework.web.jsf FacesContextUtils getRequiredWebApplicationContext

List of usage examples for org.springframework.web.jsf FacesContextUtils getRequiredWebApplicationContext

Introduction

In this page you can find the example usage for org.springframework.web.jsf FacesContextUtils getRequiredWebApplicationContext.

Prototype

public static WebApplicationContext getRequiredWebApplicationContext(FacesContext fc)
        throws IllegalStateException 

Source Link

Document

Find the root WebApplicationContext for this web app, typically loaded via org.springframework.web.context.ContextLoaderListener .

Usage

From source file:org.hdiv.phaseListeners.ConfigPhaseListener.java

public void beforePhase(PhaseEvent event) {

    if (event.getPhaseId().equals(PhaseId.RESTORE_VIEW)) {

        if (!this.initialized) {

            if (log.isDebugEnabled()) {
                log.debug("Initialize ConfigPhaseListener dependencies.");
            }// www . j av  a  2  s . co m

            FacesContext context = event.getFacesContext();
            // Check not supported features
            this.checkSupportedFeatures(context);

            // Get listener instances
            WebApplicationContext wac = FacesContextUtils.getRequiredWebApplicationContext(context);
            HDIVFacesEventListener facesEventListener = (HDIVFacesEventListener) wac
                    .getBean("HDIVFacesEventListener");

            // It is added to the servletContext to be able to consume it from components
            HDIVUtilJsf.setFacesEventListener(facesEventListener, context);
        }
    }

    if (event.getPhaseId().equals(PhaseId.RENDER_RESPONSE)) {

        FacesContext context = event.getFacesContext();
        // Add user's unique id to state
        this.addUserUniqueTokenToState(context);
    }

}

From source file:com.foreveross.modules.jsf.SpringBeanFacesELResolver.java

/**
 * Retrieve the web application context to delegate bean name resolution to.
 * <p>The default implementation delegates to FacesContextUtils.
 * @param elContext the current JSF ELContext
 * @return the Spring web application context (never {@code null})
 * @see org.springframework.web.jsf.FacesContextUtils#getRequiredWebApplicationContext
 *///  www.j  a va  2  s .c om
protected WebApplicationContext getWebApplicationContext(ELContext elContext) {
    FacesContext facesContext = FacesContext.getCurrentInstance();
    return FacesContextUtils.getRequiredWebApplicationContext(facesContext);
}

From source file:com.autentia.wuija.web.jsf.I18NSelectItemList.java

private MessageSourceAccessor getMsa() {
    final FacesContext facesContext = FacesContext.getCurrentInstance();
    if (facesContext == null) {
        // Cuando se llama a esta funcin desde los test de JUnit, no existe un FacesContext y se producir un error.
        // En este caso comprobamos que no existe el FacesContext y devolvemos un MessageSourceAccessor alternativo
        // (mock)
        return new MessageSourceAccessor(new MockMessageSource());
    }/*www .  j  a  v  a2  s  .c om*/
    final WebApplicationContext wac = FacesContextUtils.getRequiredWebApplicationContext(facesContext);
    return (MessageSourceAccessor) wac.getBean("messageSourceAccessor", MessageSourceAccessor.class);
}

From source file:org.alfresco.web.app.Application.java

/**
 * Invalidate Alfresco ticket and Web/Portlet session and clear the Security context for this thread.
 * @param context//w ww.  j  a v  a  2s. co  m
 */
public static void logOut(FacesContext context) {
    String ticket = null;
    if (Application.inPortalServer()) {
        ticket = AlfrescoFacesPortlet.onLogOut(context.getExternalContext().getRequest());
    } else {
        SessionUser user = getCurrentUser(context);
        if (user != null) {
            ticket = user.getTicket();
        }
        HttpServletRequest request = (HttpServletRequest) context.getExternalContext().getRequest();
        HttpSession session = request.getSession(false);
        if (session != null) {
            session.invalidate();
        }
    }

    // Explicitly invalidate the Alfresco ticket. This no longer happens on session expiry to allow for ticket
    // 'sharing'
    WebApplicationContext wc = FacesContextUtils.getRequiredWebApplicationContext(context);
    AuthenticationService unprotAuthService = (AuthenticationService) wc.getBean(BEAN_UNPROTECTED_AUTH_SERVICE);
    if (ticket != null) {
        unprotAuthService.invalidateTicket(ticket);
    }
    unprotAuthService.clearCurrentSecurityContext();
}

From source file:org.alfresco.web.app.Application.java

/**
 * @return Returns the repository store URL (retrieved from config service)
 *//*  w w w.jav a 2s  . c  o m*/
public static StoreRef getRepositoryStoreRef(FacesContext context) {
    return getRepositoryStoreRef(FacesContextUtils.getRequiredWebApplicationContext(context));
}

From source file:org.alfresco.web.app.Application.java

/**
 * @return Returns the root path for the application
 *///w  ww .j  a  v a  2s.c o m
public static String getRootPath(FacesContext context) {
    return getRootPath(FacesContextUtils.getRequiredWebApplicationContext(context));
}

From source file:org.alfresco.web.app.Application.java

/**
 * @return Returns the glossary folder name
 *///  w w w  .  j  a v a2 s .  c  o  m
public static String getGlossaryFolderName(FacesContext context) {
    return getGlossaryFolderName(FacesContextUtils.getRequiredWebApplicationContext(context));
}

From source file:org.alfresco.web.app.Application.java

/**
 * @return Returns the Space templates folder name
 *//*w  w w . j a va2s  .  c  o  m*/
public static String getSpaceTemplatesFolderName(FacesContext context) {
    return getSpaceTemplatesFolderName(FacesContextUtils.getRequiredWebApplicationContext(context));
}

From source file:org.alfresco.web.app.Application.java

/**
 * @return Returns the Content templates folder name
 *//*from   ww w . j  a  v  a  2 s .c o  m*/
public static String getContentTemplatesFolderName(FacesContext context) {
    return getContentTemplatesFolderName(FacesContextUtils.getRequiredWebApplicationContext(context));
}

From source file:org.alfresco.web.app.Application.java

/**
 * @return Returns the Invite Email Templates folder name
 *//*w  ww .  jav a2 s . com*/
public static String getInviteEmailTemplatesFolderName(FacesContext context) {
    return getInviteEmailTemplatesFolderName(FacesContextUtils.getRequiredWebApplicationContext(context));
}