You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Stephane Decleire <sd...@cariboo-networks.com> on 2007/01/08 14:08:08 UTC

Recursive component inclusion

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



Re: Recursive component inclusion

Posted by Stephane Decleire <sd...@cariboo-networks.com>.
Thanks Ron but i'm not sure that a graphical tree is the best solution 
for my users.
The number of categories that we manage is quite big and i'm afraid that 
the user get a bit lost ...
I would have prefer dependent dropdown boxes ...

I've tried to implement this without recursivity using a @For loop. But 
i'm faced with another problem : i can't achieve to put an EventListener 
on each combo at compile time since i don't know the number of combo 
that will be displayed ... It's the snake who bite is tail ...

--
Stéphane Decleire

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



RonPiterman a écrit :
> 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: users-unsubscribe@tapestry.apache.org
>>> For additional commands, e-mail: users-help@tapestry.apache.org
>>>
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>

Re: Recursive component inclusion

Posted by RonPiterman <rp...@gmx.net>.
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: users-unsubscribe@tapestry.apache.org
>> For additional commands, e-mail: users-help@tapestry.apache.org
>>
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: Recursive component inclusion

Posted by Stephane Decleire <sd...@cariboo-networks.com>.
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: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>

Re: Recursive component inclusion

Posted by RonPiterman <rp...@gmx.net>.
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: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: Recursive component inclusion

Posted by Roberto Ramírez Vique <ro...@gmail.com>.
Hi Stephane!

I've tried but I've never succeed, but to me there seems that tapestry has
this limitation. I think you can use a trick using the Block / RenderBlock
components , but not totally sure this will work.

hope this helps,
         r.

On 1/8/07, Stephane Decleire <sd...@cariboo-networks.com> 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
>
>
>
>


-- 
Robert Ramírez Vique
Computer Science Engineer