Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8568635
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T18:09:20+00:00 2026-06-11T18:09:20+00:00

I would like to know how to render a composite component, through Java, I

  • 0

I would like to know how to render a composite component, through Java,
I mean I have:

<myowntags:selectOneRadio>
  <f:selectItem itemValue="value0" itemLabel="This is the value 0" />
  <f:selectItem itemValue="value1" itemLabel="This is the value 1" />
  <f:selectItem itemValue="value2" itemLabel="This is the value 2" />
</myowntags:selectOneRadio>

or

<myowntags:selectOneRadio>
  <f:selectItems  value="#{controller.items}"  />
</myowntags:selectOneRadio>

and I would like to create a Java class to render it.

I know how to render a custom component without using composite, but since, to render a component I have to specify some values on the block:

<renderer>
    <component-family>javax.faces.SelectBoolean</component-family>
    <renderer-type>javax.faces.Checkbox</renderer-type>
    <renderer-class>com.myapp.CustomCheckboxRenderer</renderer-class>
</renderer>

then I get lost, because I don’t know the values of those parameters
inside the render tag for a composite component.

Thanks in advance,
Angel.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T18:09:21+00:00Added an answer on June 11, 2026 at 6:09 pm

    First, you need to have a backing component which implements NamingContainer and returns "javax.faces.NamingContainer" as component family. This is required by composite components, you can’t change that part. The UINamingContainer implementation already does that, so if you can just extend from it.

    @FacesComponent("mySelectOneRadio")
    public class MySelectOneRadio extends UINamingContainer {
        // ...
    }
    

    Or if you rather want to extend from UISelectOne, then you’d have to implement the NamingContainer interface and make sure that you return UINamingContainer.COMPONENT_FAMILY in the getFamily() override.

    Then, you need to specify it in <cc:interface componentType>.

    <cc:interface componentType="mySelectOneRadio">
    

    Note that at this step you can already perform the rendering (encoding) through Java. Just override the encodeChildren() method.

    @FacesComponent("mySelectOneRadio")
    public class MySelectOneRadio extends UINamingContainer {
    
        @Override
        public void encodeChildren(FacesContext context) throws IOException {
            ResponseWriter writer = context.getResponseWriter();
            writer.startElement("div", this);
            writer.writeText("hello world", null);
            writer.endElement("div");
        }
    
    }
    

    Coming back to your concrete question, you’d thus like to have a standalone Renderer class for this. That’s fine. For that you need to extend Renderer:

    @FacesRenderer(componentFamily=UINamingContainer.COMPONENT_FAMILY, rendererType=MySelectOneRadioRenderer.RENDERER_TYPE)
    public class MySelectOneRadioRenderer extends Renderer {
    
        public static final String RENDERER_TYPE = "com.example.MySelectOneRadio";
    
        @Override
        public void encodeChildren(FacesContext context, UIComponent component) throws IOException {
            ResponseWriter writer = context.getResponseWriter();
            writer.startElement("div", component);
            writer.writeText("hello world", null);
            writer.endElement("div");
        }
    
    }
    

    The backing component should be changed as follows in order to properly register this renderer as the default renderer (don’t override getRendererType() method! otherwise you or anyone else would be unable to change this by <renderer> in faces-config.xml):

    @FacesComponent("myComposite")
    public class MyComposite extends UINamingContainer {
    
        public MyComposite() {
            // Set default renderer.
            setRendererType(MySelectOneRadioRenderer.RENDERER_TYPE);
        }
    
    }
    

    Note that thanks to the @FacesRenderer, you don’t need to hassle with faces-config.xml.


    Whatever way you choose to encode the children, you can get component’s children just by UIComponent#getChildren(). When you’re inside MySelectOneRadio component:

    if (getChildCount() > 0) {
        for (UICompnent child : getChildren()) {
            // ...
        }
    }
    

    Or when you’re inside MySelectOneRadioRenderer renderer:

    if (component.getChildCount() > 0) {
        for (UICompnent child : component.getChildren()) {
            // ...
        }
    }
    

    To delegate to the component’s own default rendering, invoke super.encodeChildren() or component.encodeChildren(). To delegate to child’s own default rendering, invoke child.encodeAll().

    See also:

    • What is the relationship between component family, component type and renderer type?
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to know how. I have looked at this topic , and
I have blog comment forms in Django and I would like to know the
I would like to know the OpenGL Rendering settings for having a program render
Hi I would like to know how can I render output in dot.js templating
I would like to know whats the difference between using the method Render vs.
I would like to know if I can use MathJax to render LaTeX notations
I would like to know how to render the new action of another controller
i would like know some reference. I know i can googling it. but prefer
Would like to know what a programmer should know to become a good at
Would like to know the c# code to actually retrieve the IP type: Static

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.