I have been having problems with my components that are inside facets
being re-created on every faces request, despite staying on the same
view root. I just sent an email trying to figure this out last night
wondering if it was a bug with Trinidad + Facelets, but now that I
have look even more into it, it looks like a major flaw in the
Facelets mark and sweep code.

In ComponentHandler.apply(FaceletContext, UIComponent) the following
code exists:

UIComponent c = ComponentSupport.findChildByTagId(parent, id);

This call is supposed to find any component that already exists and
make sure it is kept around. If this function returns null, the
components will be re-created. The code for that function is here:

    public static final UIComponent findChildByTagId(UIComponent
parent, String id) {
        int sz = parent.getChildCount();
        if (sz > 0) {
            UIComponent c = null;
            List cl = parent.getChildren();
            String cid = null;
            while (--sz >= 0) {
                c = (UIComponent) cl.get(sz);
                cid = (String) c.getAttributes().get(MARK_CREATED);
                if (id.equals(cid)) {
                    return c;
                }
            }
        }
        return null;
    }

Immediately you should see a major piece of functionality missing.
This function never looks at the facets to find the component!

UIComponentSupport.finalizeForDeletion(UIComponent)  does look at the
facets, so at least the code won't blow up for re-creating the same
facets over and over without removing the old ones.

But the fact that facets are never found means that all components in
facets in facelet views will never be able to retain their state!

Is this bug already reported and/or fixed in a newer release (I was
not able to find it in the facelets issue tracker)?

I would categorize this as a blocker in priority.

Thank you,
Andrew

Reply via email to