do you know tacos?
there is a tree implementation there, initially created by victor - its very simple yet very powerfull.

Here is the base idee:

--------------------------------------------------------------

public abstract class Tree extends AbstractComponent{

        @Parameter(required=true)
        public abstract <T> TreeModel<T> getModel();
        
        @Parameter(required=true)
        public abstract Object getValue();
        public abstract void setValue( Object o );
        
        @Parameter(required=false)
        public abstract int getLevel();
        public abstract void setLevel( int i );
        
        @Parameter(required=true)
        public abstract String getElement();
        

        @Override
        protected void renderComponent(IMarkupWriter writer, IRequestCycle 
cycle) {
                TreeModel model = getModel();
                Iterator i = model.getRoots();
                Object o;
                while ( i.hasNext() ) {
                        o = i.next();
                        renderLevel( 0 , o , writer, cycle );
                }
        }               

private void renderLevel(int level, Object o, IMarkupWriter writer, IRequestCycle cycle) {
                setValue( o );
                if ( getBinding("level") != null )
                        setLevel ( level );
                
                writer.begin( getElement() );
                super.renderInformalParameters( writer, cycle);
                
                super.renderBody(writer, cycle);
                
                if ( getModel().isHasChildren( o )) {
                        Iterator i = getModel().getChildren( o );
                        Object child;
                        while ( i.hasNext() ) {
                                child = i.next();
                                renderLevel( level + 1 , child , writer , cycle 
);
                        }
                }
                
                writer.end( getElement());
                
        }


}


public interface TreeModel<T> {

        Iterator<T> getRoots();

        boolean isHasChildren(T o);

        Iterator<T> getChildren(T o);

}

---------------------------------------------

thats all: the body of the tree will be rendered for each item in the tree, surrounding levels with the "element" parameter.

Note that this implementation has no state, all nodes are always displayed - adding state is however quite straightforward...


If this is not enough - take a look at the tacos Tree - I think its not so easy to understand nowadays since its full of ajax functionality, which makes the code not as transaparetn...

Cheers,
Ron



Stephane Decleire wrote:
I try to implement a component to let a user choose a category in a tree.
So, i would like to show him at each level of the tree the subcategories in a combobox.
My problem is that i don't know at compile time the depth of the tree.

That's why i thought that each node of the tree of categories could have been a tapestry component which present the children of the current category to the user ... and that leads to recursivity !

--
Stéphane Decleire

Cariboo Networks SARL
05 56 57 99 20 / 06 63 78 69 06
www.bebe-nounou.fr



RonPiterman a écrit :
AFAIK this can not be done directly, but there are solutions for different problems like displaying a tree using recursion on the model level - what exactly are you trying to achieve?
Cheers,
Ron



Stephane Decleire wrote:
Hi,

I wonder if there is a way for a tapestry component to include itself (in a recursive way). Despite I have in my template a condition to exit from this infinite loop, it ends up in a stack overflow error. I suppose tapestry goes in an infinite loop when it tries to instanciate the components for the page :-( (far before reading my template).

Has anybody achieved such an implementation ?

--
Stéphane Decleire





---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to