Search in sources :

Example 1 with ComponentSystemEventListener

use of javax.faces.event.ComponentSystemEventListener in project liferay-faces-bridge-ext by liferay.

the class ResourceRendererLiferayImpl method processEvent.

/**
 * Since the Mojarra {@link com.sun.faces.renderkit.html_basic.ScriptStyleBaseRenderer} class implements {@link
 * ComponentSystemEventListener}, this class must implement that interface too, since this is a wrapper type of
 * class. Mojarra uses this method to intercept {@link PostAddToViewEvent} in order to add script and link resources
 * to the head (if the target attribute has a value of "head").
 */
@Override
public void processEvent(ComponentSystemEvent event) throws AbortProcessingException {
    // associated with the specified event as a resource on the view root.
    if (wrappedRenderer instanceof ComponentSystemEventListener) {
        ComponentSystemEventListener wrappedListener = (ComponentSystemEventListener) wrappedRenderer;
        wrappedListener.processEvent(event);
    } else {
        logger.debug("Wrapped renderer=[{0}] does not implement ComponentSystemEventListener", wrappedRenderer);
    }
}
Also used : ComponentSystemEventListener(javax.faces.event.ComponentSystemEventListener)

Example 2 with ComponentSystemEventListener

use of javax.faces.event.ComponentSystemEventListener in project liferay-faces-bridge-impl by liferay.

the class ResourcesRenderedInHeadTestBean method preRenderHeadListener.

/**
 * This method causes each head resource to render an id attribute containing the resource name or client id if the
 * resource name is unavailable. See {@link ResponseWriterResourceIdImpl} and the comments below for more details.
 */
public void preRenderHeadListener(ComponentSystemEvent componentSystemEvent) throws AbortProcessingException {
    // Obtain all head resources.
    UIComponent uiComponent = componentSystemEvent.getComponent();
    List<UIComponent> children = uiComponent.getChildren();
    FacesContext facesContext = FacesContext.getCurrentInstance();
    UIViewRoot uiViewRoot = facesContext.getViewRoot();
    List<UIComponent> componentResources = uiViewRoot.getComponentResources(facesContext, "head");
    List<UIComponent> headResources = new ArrayList<UIComponent>(children);
    headResources.addAll(componentResources);
    // ResponseWriter to an instance of ResponseWriterResourceIdImpl.
    for (UIComponent headResource : headResources) {
        String rendererType = headResource.getRendererType();
        if ((headResource instanceof UIOutput) && (rendererType.equals("javax.faces.resource.Script") || rendererType.equals("javax.faces.resource.Stylesheet"))) {
            headResource.subscribeToEvent(PreRenderComponentEvent.class, new ComponentSystemEventListener() {

                @Override
                public void processEvent(ComponentSystemEvent componentSystemEvent) throws AbortProcessingException {
                    FacesContext facesContext = FacesContext.getCurrentInstance();
                    ResponseWriter responseWriter = facesContext.getResponseWriter();
                    if (!(responseWriter instanceof ResponseWriterResourceIdImpl)) {
                        facesContext.setResponseWriter(new ResponseWriterResourceIdImpl(responseWriter));
                    }
                }
            });
        }
    }
}
Also used : FacesContext(javax.faces.context.FacesContext) ComponentSystemEventListener(javax.faces.event.ComponentSystemEventListener) UIComponent(javax.faces.component.UIComponent) ArrayList(java.util.ArrayList) UIOutput(javax.faces.component.UIOutput) ResponseWriter(javax.faces.context.ResponseWriter) ComponentSystemEvent(javax.faces.event.ComponentSystemEvent) AbortProcessingException(javax.faces.event.AbortProcessingException) UIViewRoot(javax.faces.component.UIViewRoot)

Example 3 with ComponentSystemEventListener

use of javax.faces.event.ComponentSystemEventListener in project liferay-faces-bridge-impl by liferay.

the class ResourceRendererBridgeImpl method processEvent.

/**
 * Since the Mojarra {@link com.sun.faces.renderkit.html_basic.ScriptStyleBaseRenderer} class implements {@link
 * ComponentSystemEventListener}, this class must implement that interface too, since this is a wrapper type of
 * class. Mojarra uses this method to intercept {@link PostAddToViewEvent} in order to add script and link resources
 * to the head (if the target attribute has a value of "head").
 */
@Override
public void processEvent(ComponentSystemEvent event) throws AbortProcessingException {
    // associated with the specified event as a resource on the view root.
    if (wrappedRenderer instanceof ComponentSystemEventListener) {
        ComponentSystemEventListener wrappedListener = (ComponentSystemEventListener) wrappedRenderer;
        wrappedListener.processEvent(event);
    } else {
        logger.debug("Wrapped renderer=[{0}] does not implement ComponentSystemEventListener", wrappedRenderer);
    }
}
Also used : ComponentSystemEventListener(javax.faces.event.ComponentSystemEventListener)

Example 4 with ComponentSystemEventListener

use of javax.faces.event.ComponentSystemEventListener in project liferay-faces-bridge-impl by liferay.

the class ResourceRendererImpl method processEvent.

/**
 * Since the Mojarra com.sun.faces.renderkit.html_basic.ScriptStyleBaseRenderer class implements {@link
 * ComponentSystemEventListener}, this class must implement that interface too, since this is a wrapper type of
 * class. Mojarra uses this method to intercept {@link PostAddToViewEvent} in order to add script and link resources
 * to the head (if the target attribute has a value of "head").
 */
@Override
public void processEvent(ComponentSystemEvent event) throws AbortProcessingException {
    // associated with the specified event as a resource on the view root.
    if (wrappedRenderer instanceof ComponentSystemEventListener) {
        ComponentSystemEventListener wrappedListener = (ComponentSystemEventListener) wrappedRenderer;
        wrappedListener.processEvent(event);
    } else {
        logger.debug("Wrapped renderer=[{0}] does not implement ComponentSystemEventListener", wrappedRenderer);
    }
}
Also used : ComponentSystemEventListener(javax.faces.event.ComponentSystemEventListener)

Example 5 with ComponentSystemEventListener

use of javax.faces.event.ComponentSystemEventListener in project liferay-faces-alloy by liferay.

the class OutputScriptStylesheetRendererBase method processEvent.

@Override
public void processEvent(ComponentSystemEvent componentSystemEvent) throws AbortProcessingException {
    FacesContext facesContext = FacesContext.getCurrentInstance();
    Renderer delegateRenderer = getDelegateRenderer(facesContext);
    if (delegateRenderer instanceof ComponentSystemEventListener) {
        ComponentSystemEventListener delegateComponentSystemEventListener = (ComponentSystemEventListener) delegateRenderer;
        delegateComponentSystemEventListener.processEvent(componentSystemEvent);
    }
}
Also used : FacesContext(javax.faces.context.FacesContext) ComponentSystemEventListener(javax.faces.event.ComponentSystemEventListener) Renderer(javax.faces.render.Renderer)

Aggregations

ComponentSystemEventListener (javax.faces.event.ComponentSystemEventListener)5 FacesContext (javax.faces.context.FacesContext)2 ArrayList (java.util.ArrayList)1 UIComponent (javax.faces.component.UIComponent)1 UIOutput (javax.faces.component.UIOutput)1 UIViewRoot (javax.faces.component.UIViewRoot)1 ResponseWriter (javax.faces.context.ResponseWriter)1 AbortProcessingException (javax.faces.event.AbortProcessingException)1 ComponentSystemEvent (javax.faces.event.ComponentSystemEvent)1 Renderer (javax.faces.render.Renderer)1