I'm trying to create a JSF component that would be composed of two
child components: an UIInput and a HtmlSelectManyListbox. The user
would be able to either use the text field or listbox to input a field
value.

How should the child components be created? Currently I'm doing it in
encodeBegin, when the component does not have any children. Is this a
proper way to create subcomponents?

If I don't override getRendersChildren, are child components rendered
automatically or should they be rendered manually? If child rendering
needs to be triggered explicitly, which methods should be called?

Since only the child components have state, there shouldn't be any
need to implement state handling in the parent, right?


Here's what my component looks like:

public class MyInputSelect extends UIInput {
   public MyInputSelect() {
       super();
       setRendererType(null);
   }

   public void encodeBegin(FacesContext ctx) throws IOException {
       if(this.getChildren().isEmpty()) createComponents();
   }

   private void createComponents() {
       
this.getChildren().add((UIInput)app.createComponent(UIInput.COMPONENT_TYPE));
        HtmlSelectManyListbox menu = 
(HtmlSelectManyListbox)app.createComponent();
        // populate menu
       this.getChildren().add(menu);
   }

   public void decode(FacesContext ctx) {
       // read child component values and set components value accordingly
   }

   public String getFamily() { return COMPONENT_FAMILY; }       
}

Reply via email to