Hi,

you should not use viewRoot.createUniqueId() for your components,
this is the same as not assigning ids.
The rest seems ok for me. You still have problems?

Regards,
 Volker



2007/3/17, Marko Asplund <[EMAIL PROTECTED]>:
Volker Weber wrote:
> > My current problems are related to container components. When I remove
> > container components odd things happen. Removing component a results
> > in the entire component subtree not being rendered.
>
> ? Maybe i don't understand you correct, if you remove the parent why
> did you expect the children are rendered?
>
>  > If I remove
>  > container b I fail to get any response for the HTTP request,
>
> > and if I
> > remove both I get an error about MyFaces not being able to add a child
> > node (see below).
>
> What did you mean with remove both ? When you removing a the entire
> subtree is removed.

> Plese post the code for adding an removing. did you already assign
> uniqe ids to all created components, the exception says someting about
> dublicate ids. Also add ids to all tags to identifiy the problematic
> components.

I'm assigning IDs explicitly. While going through the code a minute
ago I found a flaw that was causing one problem (in one particular
case a container component was added as its own child).

What I meant by "removing a container component", was that I modified
the code to omit a container from the hierarchy and adding its
children directly as children of the omitted component's parent.

Currently, if I remove the h:panelGrid element from the view, my
custom component tree is not rendered at all. I'll probably want to
include my component tree in a some container component such as
h:panelGrid but I'd just like to know why this happens.

I've done some changes to the code posted earlier, here's the code in
a somewhat simplified form. Are there any potential problems with the
way the component hierarchy is built?

<h:form>
  <h:panelGrid>
      <my:inputSelectSet value="#{myBean.items}"/>
  </h:panelGrid>
</h:form>

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

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

    private void initializeComponent() {
        for(int i = 0; i<5; i++)
            addSelectInputParameter(this, app);
    }

    private void addSelectInputParameter(UIComponent container,
Application app) {
        MyInputSelect sip =
(MyInputSelect)app.createComponent(MyInputSelect.COMPONENT_TYPE);
        sip.setId(getId());
        sip.initializeComponent();

        HtmlOutputLabel l =
(HtmlOutputLabel)app.createComponent(HtmlOutputLabel.COMPONENT_TYPE);
        l.setId(getId());

        HtmlPanelGroup group =
(HtmlPanelGroup)app.createComponent(HtmlPanelGroup.COMPONENT_TYPE);
        group.setId(getId());
        group.getChildren().add(l);
        group.getChildren().add(sip);

        container.getChildren().add(group);
    }

    public String getFamily() { return COMPONENT_FAMILY; }

    private String getId() { return
FacesContext.getCurrentInstance().getViewRoot().createUniqueId(); }
}

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

    public void initializeComponent() {
        Application app = FacesContext.getCurrentInstance().getApplication();
        UIInput input = (UIInput)app.createComponent(UIInput.COMPONENT_TYPE);
        input.setId(getId());
        this.getChildren().add(input);

        HtmlSelectManyListbox menu =
(HtmlSelectManyListbox)app.createComponent(HtmlSelectManyListbox.COMPONENT_TYPE);
        menu.setId(getId());

        List<SelectItem> items = new ArrayList<SelectItem>();
        for(int i = 0; i < 5; i++)
            items.add(new SelectItem(new String(i), new String(i));
        UISelectItems selectItems = new UISelectItems();
        selectItems.setId(getId());
        selectItems.setValue(items);
        menu.getChildren().add(selectItems);

        this.getChildren().add(menu);
    }

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

    public String getFamily() { return COMPONENT_FAMILY; }

    private String getId() { return
FacesContext.getCurrentInstance().getViewRoot().createUniqueId(); }
}

Reply via email to