Search in sources :

Example 16 with Renderer

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

the class AbstractButtonRenderer method encodeEnd.

@Override
public void encodeEnd(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.encodeEnd(facesContext, nodeMenuNav);
    } else {
        ResponseWriter responseWriter = facesContext.getResponseWriter();
        responseWriter.endElement(BUTTON);
    }
}
Also used : ResponseWriter(javax.faces.context.ResponseWriter) UIComponent(javax.faces.component.UIComponent) RenderKit(javax.faces.render.RenderKit) Renderer(javax.faces.render.Renderer)

Example 17 with Renderer

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

the class AbstractButtonRenderer method getConvertedValue.

@Override
public Object getConvertedValue(FacesContext facesContext, UIComponent uiComponent, Object submittedValue) throws ConverterException {
    if (hasMenu(uiComponent)) {
        UIComponent nodeMenuNav = NodeMenuNavFactory.getNodeMenuNav(uiComponent);
        RenderKit renderKit = facesContext.getRenderKit();
        Renderer nodeMenuNavRenderer = renderKit.getRenderer(nodeMenuNav.getFamily(), nodeMenuNav.getRendererType());
        return nodeMenuNavRenderer.getConvertedValue(facesContext, nodeMenuNav, submittedValue);
    } else {
        return super.getConvertedValue(facesContext, uiComponent, submittedValue);
    }
}
Also used : UIComponent(javax.faces.component.UIComponent) RenderKit(javax.faces.render.RenderKit) Renderer(javax.faces.render.Renderer)

Example 18 with Renderer

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

the class AbstractButtonRenderer method encodeBegin.

@Override
public void encodeBegin(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.encodeBegin(facesContext, nodeMenuNav);
    } else {
        ResponseWriter responseWriter = facesContext.getResponseWriter();
        // It is not possible for the ButtonResponseWriter to intercept writing of the input element that is
        // rendered by the JSF runtime, because endElement("input") may be called in either encodeBegin() or
        // encodeEnd(). Button requires that endElement() be called in encodeEnd(), so that children can be added to
        // the button if neccessary.
        responseWriter.startElement(BUTTON, uiComponent);
        Map<String, Object> attributes = uiComponent.getAttributes();
        Boolean autofocus = (Boolean) attributes.get(AUTOFOCUS);
        if (autofocus != null) {
            responseWriter.writeAttribute(AUTOFOCUS, autofocus, AUTOFOCUS);
        }
        // Do not delegate the writing of the class or style attributes because we need to apply certain default
        // classes.
        StringBuilder classNames = new StringBuilder();
        classNames.append(DEFAULT_BUTTON_CSS_CLASSES);
        boolean disabled = (Boolean) attributes.get(DISABLED);
        if (disabled) {
            classNames.append(" ");
            classNames.append(DISABLED_BUTTON_CSS_CLASSES);
        }
        RendererUtil.encodeStyleable(responseWriter, (Styleable) uiComponent, classNames.toString());
        // Do not delegate the writing of the disabled attribute because the JSF runtime may disable the button
        // programmatically based on navigation case matching.
        responseWriter.writeAttribute("disabled", disabled, "disabled");
        // Do not delegate the writing of the type attribute because the JSF runtime hard codes the type for button.
        String type = (String) attributes.get("type");
        responseWriter.writeAttribute("type", type, "type");
        // Determine if we should delegate the rendering of onclick or render it ourselves.
        Boolean delegateOnclick = Boolean.TRUE;
        if (uiComponent instanceof HtmlOutcomeTargetButton) {
            HtmlOutcomeTargetButton htmlOutcomeTargetButton = (HtmlOutcomeTargetButton) uiComponent;
            if (htmlOutcomeTargetButton.getOutcome() == null) {
                delegateOnclick = Boolean.FALSE;
                String onclick = htmlOutcomeTargetButton.getOnclick();
                if (onclick != null) {
                    // Do not delegate the writing of the onclick attribute because the JSF runtime assumes that it
                    // should include navigation, and we do not need to navigate in this case.
                    responseWriter.writeAttribute("onclick", onclick, "onclick");
                }
            }
        }
        // Do not delegate the writing of the onfocus attribute because we need to supply a script to modify the css
        // class.
        String onfocus = (String) attributes.get(ONFOCUS);
        if (onfocus == null) {
            onfocus = RETURN_FALSE;
        }
        StringBuilder onfocusBuilder = new StringBuilder();
        onfocusBuilder.append(DEFAULT_ONFOCUS);
        onfocusBuilder.append(onfocus);
        responseWriter.writeAttribute(ONFOCUS, onfocusBuilder.toString(), ONFOCUS);
        // Do not delegate the writing of the onblur attribute because we need to supply a script to modify the css
        // class.
        String onblur = (String) attributes.get(ONBLUR);
        if (onblur == null) {
            onblur = RETURN_FALSE;
        }
        StringBuilder onblurBuilder = new StringBuilder();
        onblurBuilder.append(DEFAULT_ONBLUR);
        onblurBuilder.append(onblur);
        responseWriter.writeAttribute(ONBLUR, onblurBuilder.toString(), ONBLUR);
        // Do not delegate the writing of the value attribute because the JSF runtime may not render value
        Object value = (Object) attributes.get("value");
        if (value != null) {
            responseWriter.writeAttribute("value", value.toString(), "value");
        }
        // Delegate to the JSF implementation's renderer while using our own ButtonResponseWriter to control the
        // output.
        ButtonResponseWriter buttonResponseWriter = new ButtonResponseWriter(responseWriter, delegateOnclick);
        super.encodeBegin(facesContext, uiComponent, buttonResponseWriter);
        facesContext.getAttributes().put(FACES_RUNTIME_SRC, buttonResponseWriter.getSrc());
    }
}
Also used : ResponseWriter(javax.faces.context.ResponseWriter) UIComponent(javax.faces.component.UIComponent) RenderKit(javax.faces.render.RenderKit) Renderer(javax.faces.render.Renderer) HtmlOutcomeTargetButton(javax.faces.component.html.HtmlOutcomeTargetButton)

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