Search in sources :

Example 1 with Renderer

use of javax.faces.render.Renderer in project liferay-faces-alloy by liferay.

the class AbstractButtonRenderer method encodeChildren.

@Override
public void encodeChildren(FacesContext facesContext, UIComponent uiComponent) throws IOException {
    if (hasMenu(uiComponent)) {
        UIComponent nodeMenuNav = NodeMenuNavFactory.getNodeMenuNav(uiComponent);
        RenderKit renderKit = facesContext.getRenderKit();
        Renderer nodeMenuNavRenderer = renderKit.getRenderer(nodeMenuNav.getFamily(), nodeMenuNav.getRendererType());
        nodeMenuNavRenderer.encodeChildren(facesContext, nodeMenuNav);
    } else {
        ResponseWriter responseWriter = facesContext.getResponseWriter();
        Map<String, Object> attributes = uiComponent.getAttributes();
        // Do not delegate the writing of the image attribute because the image needs to be a child rather than an
        // attribute of the button.
        String image = (String) attributes.get(IMAGE);
        if (image != null) {
            String src = (String) facesContext.getAttributes().remove(FACES_RUNTIME_SRC);
            if (src != null) {
                responseWriter.startElement("img", uiComponent);
                responseWriter.writeAttribute("src", src, IMAGE);
                responseWriter.endElement("img");
            }
        } else {
            if (getVisualChildCount(uiComponent) == 0) {
                // Do not delegate the writing of the value attribute because the value needs to be a child rather
                // than an attribute of the button.
                Object value = (String) attributes.get("value");
                if (value != null) {
                    responseWriter.writeText(value.toString(), "value");
                }
            }
        }
        super.encodeChildren(facesContext, uiComponent);
    }
}
Also used : ResponseWriter(javax.faces.context.ResponseWriter) UIComponent(javax.faces.component.UIComponent) RenderKit(javax.faces.render.RenderKit) Renderer(javax.faces.render.Renderer)

Example 2 with Renderer

use of javax.faces.render.Renderer in project liferay-faces-bridge-impl by liferay.

the class ResourceRendererImplTest method testSaveRestoreStateFACES_3280.

@Test
public void testSaveRestoreStateFACES_3280() {
    Renderer renderer = new RendererMockImpl();
    ResourceRendererImpl resourceRendererImpl = new ResourceRendererImpl(renderer);
    Object state = resourceRendererImpl.saveState(null);
    Assert.assertEquals(renderer.getClass(), state);
    resourceRendererImpl = new ResourceRendererImpl();
    Assert.assertNull(resourceRendererImpl.getWrapped());
    resourceRendererImpl.restoreState(null, state);
    Assert.assertNotNull(resourceRendererImpl.getWrapped());
}
Also used : Renderer(javax.faces.render.Renderer) Test(org.junit.Test)

Example 3 with Renderer

use of javax.faces.render.Renderer in project primefaces by primefaces.

the class UIData method encodeBegin.

@Override
public void encodeBegin(FacesContext context) throws IOException {
    preEncode(context);
    if (context == null) {
        throw new NullPointerException();
    }
    pushComponentToEL(context, null);
    if (!isRendered()) {
        return;
    }
    context.getApplication().publishEvent(context, PreRenderComponentEvent.class, this);
    String rendererType = getRendererType();
    if (rendererType != null) {
        Renderer renderer = getRenderer(context);
        if (renderer != null) {
            renderer.encodeBegin(context, this);
        }
    }
}
Also used : Renderer(javax.faces.render.Renderer)

Example 4 with Renderer

use of javax.faces.render.Renderer in project primefaces by primefaces.

the class CascadeSelect method queueEvent.

@Override
public void queueEvent(FacesEvent event) {
    FacesContext context = getFacesContext();
    if (ComponentUtils.isRequestSource(this, context) && event instanceof AjaxBehaviorEvent) {
        Map<String, String> params = context.getExternalContext().getRequestParameterMap();
        String eventName = params.get(Constants.RequestParams.PARTIAL_BEHAVIOR_EVENT_PARAM);
        FacesEvent wrapperEvent = null;
        AjaxBehaviorEvent behaviorEvent = (AjaxBehaviorEvent) event;
        if ("itemSelect".equals(eventName)) {
            Renderer renderer = ComponentUtils.getUnwrappedRenderer(context, "javax.faces.SelectOne", "javax.faces.Listbox");
            Object item = renderer.getConvertedValue(context, this, getSubmittedValue());
            wrapperEvent = new SelectEvent(this, behaviorEvent.getBehavior(), item);
            wrapperEvent.setPhaseId(behaviorEvent.getPhaseId());
        }
        super.queueEvent(wrapperEvent);
    } else {
        super.queueEvent(event);
    }
}
Also used : FacesContext(javax.faces.context.FacesContext) Renderer(javax.faces.render.Renderer) AjaxBehaviorEvent(javax.faces.event.AjaxBehaviorEvent) FacesEvent(javax.faces.event.FacesEvent) SelectEvent(org.primefaces.event.SelectEvent)

Example 5 with Renderer

use of javax.faces.render.Renderer in project primefaces by primefaces.

the class UITabPanel method process.

public void process(FacesContext faces, PhaseId phase) {
    // stop if not rendered
    if (!isRendered()) {
        return;
    }
    // validate attributes
    validateAttributes();
    // reset index
    captureScopeValues();
    setIndex(-1);
    try {
        // has children
        if (getChildCount() > 0) {
            boolean dynamic = isDynamic();
            int i = getOffset();
            int end = getSize();
            int step = getStep();
            end = (end >= 0) ? i + end : Integer.MAX_VALUE - 1;
            // grab renderer
            String rendererType = getRendererType();
            Renderer renderer = null;
            if (rendererType != null) {
                renderer = getRenderer(faces);
            }
            _count = 0;
            setIndex(i);
            while (i <= end && isIndexAvailable()) {
                if (PhaseId.RENDER_RESPONSE.equals(phase) && renderer != null) {
                    renderer.encodeChildren(faces, this);
                } else {
                    for (int j = 0, childCount = getChildCount(); j < childCount; j++) {
                        UIComponent child = getChildren().get(j);
                        if (dynamic && child instanceof Tab && !((Tab) child).isLoaded(i)) {
                            continue;
                        }
                        if (PhaseId.APPLY_REQUEST_VALUES.equals(phase)) {
                            child.processDecodes(faces);
                        } else if (PhaseId.PROCESS_VALIDATIONS.equals(phase)) {
                            child.processValidators(faces);
                        } else if (PhaseId.UPDATE_MODEL_VALUES.equals(phase)) {
                            child.processUpdates(faces);
                        } else if (PhaseId.RENDER_RESPONSE.equals(phase)) {
                            child.encodeAll(faces);
                        }
                    }
                }
                ++_count;
                i += step;
                setIndex(i);
            }
        }
    } catch (IOException e) {
        throw new FacesException(e);
    } finally {
        setIndex(-1);
        restoreScopeValues();
    }
}
Also used : Tab(org.primefaces.component.tabview.Tab) Renderer(javax.faces.render.Renderer) IOException(java.io.IOException) FacesException(javax.faces.FacesException)

Aggregations

Renderer (javax.faces.render.Renderer)18 UIComponent (javax.faces.component.UIComponent)7 RenderKit (javax.faces.render.RenderKit)7 FacesContext (javax.faces.context.FacesContext)6 ResponseWriter (javax.faces.context.ResponseWriter)4 IOException (java.io.IOException)3 FacesException (javax.faces.FacesException)3 ExternalContext (javax.faces.context.ExternalContext)2 AjaxBehaviorEvent (javax.faces.event.AjaxBehaviorEvent)2 Test (org.junit.Test)2 SelectEvent (org.primefaces.event.SelectEvent)2 ResourceComponent (com.liferay.faces.bridge.component.internal.ResourceComponent)1 FileUploadRendererPortletImpl (com.liferay.faces.bridge.renderkit.bridge.internal.FileUploadRendererPortletImpl)1 InlineScript (com.liferay.faces.bridge.renderkit.html_basic.internal.InlineScript)1 HeadRendererICEfacesImpl (com.liferay.faces.bridge.renderkit.icefaces.internal.HeadRendererICEfacesImpl)1 FormRendererPrimeFacesImpl (com.liferay.faces.bridge.renderkit.primefaces.internal.FormRendererPrimeFacesImpl)1 HeadRendererPrimeFacesImpl (com.liferay.faces.bridge.renderkit.primefaces.internal.HeadRendererPrimeFacesImpl)1 FileUploadRendererRichFacesImpl (com.liferay.faces.bridge.renderkit.richfaces.internal.FileUploadRendererRichFacesImpl)1 Product (com.liferay.faces.util.product.Product)1 ProductFactory (com.liferay.faces.util.product.ProductFactory)1