Search in sources :

Example 1 with ConfiguredSystemEventListener

use of com.liferay.faces.util.config.ConfiguredSystemEventListener in project liferay-faces-bridge-impl by liferay.

the class ApplicationCompatImpl method subscribeToJSF2SystemEvent.

protected void subscribeToJSF2SystemEvent(ConfiguredSystemEventListener configuredSystemEventListener) {
    try {
        ClassLoader classLoader = TCCLUtil.getThreadContextClassLoaderOrDefault(getClass());
        @SuppressWarnings("unchecked") Class<? extends SystemEvent> systemEventClass = (Class<? extends SystemEvent>) classLoader.loadClass(configuredSystemEventListener.getSystemEventClass());
        @SuppressWarnings("unchecked") Class<? extends SystemEventListener> systemEventListenerClass = (Class<? extends SystemEventListener>) classLoader.loadClass(configuredSystemEventListener.getSystemEventListenerClass());
        SystemEventListener systemEventListener = systemEventListenerClass.newInstance();
        logger.debug("Subscribing UIViewRootBridgeImpl for systemEventClass=[{0}] systemEventListener=[{1}]", systemEventClass, systemEventListener);
        subscribeToEvent(systemEventClass, UIViewRootBridgeImpl.class, systemEventListener);
    } catch (Exception e) {
        logger.error(e);
    }
}
Also used : SystemEvent(javax.faces.event.SystemEvent) SystemEventListener(javax.faces.event.SystemEventListener) ConfiguredSystemEventListener(com.liferay.faces.util.config.ConfiguredSystemEventListener)

Example 2 with ConfiguredSystemEventListener

use of com.liferay.faces.util.config.ConfiguredSystemEventListener in project liferay-faces-bridge-impl by liferay.

the class ApplicationImpl method createComponent.

/**
 * This method provides the ability to supply an instance of the bridge API's {@link
 * PortletNamingContainerUIViewRoot} class which properly handles namespacing of "id" attributes for portlets.
 *
 * @see  Application#createComponent(String)
 */
@Override
@SuppressWarnings("unchecked")
public UIComponent createComponent(String componentType) throws FacesException {
    FacesContext facesContext = FacesContext.getCurrentInstance();
    if (componentType.equals(UIViewRoot.COMPONENT_TYPE) && BridgeUtil.isPortletRequest(facesContext)) {
        // to cleanup @ViewScoped managed-beans.
        if (subscribeToEventsAtRuntime) {
            // order to ensure that it only happens once.
            synchronized (subscribeToEventsAtRuntime) {
                // Need to check again within the synchronization block, just in case.
                if (subscribeToEventsAtRuntime) {
                    BridgeConfig bridgeConfig = RequestMapUtil.getBridgeConfig(facesContext);
                    List<ConfiguredSystemEventListener> configuredSystemEventListeners = (List<ConfiguredSystemEventListener>) bridgeConfig.getAttributes().get(BridgeConfigAttributeMap.CONFIGURED_SYSTEM_EVENT_LISTENERS);
                    if (configuredSystemEventListeners != null) {
                        for (ConfiguredSystemEventListener configuredSystemEventListener : configuredSystemEventListeners) {
                            if (UIVIEWROOT_FQCN.equals(configuredSystemEventListener.getSourceClass())) {
                                subscribeToJSF2SystemEvent(configuredSystemEventListener);
                            }
                        }
                    }
                }
                subscribeToEventsAtRuntime = false;
            }
        }
        return new UIViewRootBridgeImpl();
    } else {
        return getWrapped().createComponent(componentType);
    }
}
Also used : FacesContext(javax.faces.context.FacesContext) UIViewRootBridgeImpl(com.liferay.faces.bridge.component.internal.UIViewRootBridgeImpl) BridgeConfig(javax.portlet.faces.BridgeConfig) List(java.util.List) ConfiguredSystemEventListener(com.liferay.faces.util.config.ConfiguredSystemEventListener)

Aggregations

ConfiguredSystemEventListener (com.liferay.faces.util.config.ConfiguredSystemEventListener)2 UIViewRootBridgeImpl (com.liferay.faces.bridge.component.internal.UIViewRootBridgeImpl)1 List (java.util.List)1 FacesContext (javax.faces.context.FacesContext)1 SystemEvent (javax.faces.event.SystemEvent)1 SystemEventListener (javax.faces.event.SystemEventListener)1 BridgeConfig (javax.portlet.faces.BridgeConfig)1