jakartaee / faces

Jakarta Faces
Other
108 stars 55 forks source link

UIData: do not limit children to be UIColumn only #1905

Open Rapster opened 8 months ago

Rapster commented 8 months ago

According to the spec:

Only children of type UIColumn should be processed by renderers associated with this component.

But why stop there? When what makes this component quite powerful is the "saving state per row algorithm"... It's gonna be a repeat of https://github.com/jakartaee/faces/issues/1837, but in PrimeFaces we had to create a custom UIData to support other kind of children (like p:columns). Also, UIRepeat seem very similar to UIData and yet are two different component

IMO, the spec should "allow" UIData to have more children than just UIColumn so they can be processed. Also, it should handle cases where children is also UIData (that would solve this problem https://github.com/jakartaee/faces/issues/1837 I think).

As a quick example what it could look like in UIData:

    private boolean visitColumnsAndColumnFacets(VisitContext context, VisitCallback callback, boolean visitRows) {
        if (visitRows) {
            setRowIndex(-1);
        }
        if (getChildCount() > 0) {
            for (UIComponent column : getChildren()) {
                if(column instanceof UIData) {
                    UIData child = (UIData) column;
                    for (int j = 0; j < child.getRowCount(); j++) {
                        child.setRowIndex(j);
                        boolean value = visitColumnFacets(context, callback, child);
                        if (value) {
                            child.setRowIndex(-1);
                            return true;
                        }
                    }
                    child.setRowIndex(-1);
                }
                else if (isEligibleChildren(column)) {
                    if (visitColumnFacets(context, callback, column)) {
                        return true;
                    }
                }
            }
        }

        return false;
    }

Where UIData#isEligibleChildren() returns whether or not children should be visited/processed etc. (where this method is protected and can be overrided)

WDYT?

BalusC commented 6 months ago

UIData should also have a reusable superclass in API which is also shared with UIRepeat etc https://github.com/jakartaee/faces/issues/963