JSF 2.0: How to override base renderers with custom ones?

后端 未结 2 1328
星月不相逢
星月不相逢 2020-12-03 22:43

I am trying to override renderer for h:selectBooleanCheckbox (for the reasons explained here):

However, I find it impossible to register my renderer. I

相关标签:
2条回答
  • 2020-12-03 23:08

    Your initial <renderer> declaration looks fine, so I tried it here.

    package com.myapp;
    
    import java.io.IOException;
    
    import javax.faces.component.UIComponent;
    import javax.faces.context.FacesContext;
    
    import com.sun.faces.renderkit.html_basic.CheckboxRenderer;
    
    public class CustomCheckboxRenderer extends CheckboxRenderer {
    
        public CustomCheckboxRenderer() {
            System.out.println("CustomCheckboxRenderer <init>");
        }
    
        @Override
        public void decode(FacesContext context, UIComponent component) {
            System.out.println("CustomCheckboxRenderer decode()");
            super.decode(context, component);
        }
    
        @Override
        public void encodeBegin(FacesContext context, UIComponent component) throws IOException {
            System.out.println("CustomCheckboxRenderer encodeBegin()");
            super.encodeBegin(context, component);
        }
    
        @Override
        public void encodeEnd(FacesContext context, UIComponent component) throws IOException {
            System.out.println("CustomCheckboxRenderer encodeEnd()");
            super.encodeEnd(context, component);
        }
    
    }
    

    It works fine. All get printed to stdout. Your problem lies somewhere else. I was using Mojarra 2.0.3 on Tomcat 7.0.5.

    0 讨论(0)
  • 2020-12-03 23:14

    I add renderers to my faces-config.xml like so:

    <faces-config>
        <!--elided-->
    <render-kit>
        <render-kit-id>HTML_BASIC</render-kit-id>
        <renderer>
            <display-name>MyRenderer</display-name>
            <component-family>javax.faces.Output</component-family>
            <renderer-type>foo.MyRenderer</renderer-type>
            <renderer-class>foo.MyRenderer</renderer-class>
            <!-- TODO: attributes for tooling -->
    

    You don't need to (and shouldn't) declare a new render kit class in this scenario.

    0 讨论(0)
提交回复
热议问题