You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by drgorb <ma...@tapestryforums.com> on 2006/02/02 22:42:30 UTC

getContainer()

Hi,

I try to use getContainer() inside a component to get at its parent, but the method allways returns the page object, no matter what.

Are ther special conditions for this to work? Is there special configuration?

In the following example, the IComponent parent is allways the Home page and never the enclosing tag. I've checked that with my eclipse debuger.

HTML:
	
		
			
				
				
			
			
			
			
			
		
	

The Label.java renderComponent method:
the class extends BaseComponent

  @Override
  protected void renderComponent(IMarkupWriter writer, IRequestCycle cycle) {
    IComponent parent=getContainer();
    super.renderComponent(writer, cycle);
  }


-------------------- m2f --------------------

Sent from www.TapestryForums.com

Read this topic online here: <<topic_link>>

http://www.tapestryforums.com/viewtopic.php?p=14264#14264

-------------------- m2f --------------------



Re: getContainer()

Posted by Kent Tong <ke...@cpttm.org.mo>.
drgorb <maillist <at> tapestryforums.com> writes:

> I try to use getContainer() inside a component to get at its parent, but the 
> method allways returns the page object, no matter what.

Try:

class Record ... {
  final static String KEY="ActiveRecord";

  void prepareForRender(IRequestCycle cycle) {
    super.prepareForRender(cycle);
    cycle.setAttribute(KEY, this);
  }
  void cleanupAfterRender(IRequestCycle cycle) {
    cycle.removeAttribute(KEY);
    super.cleanupAfterRender(cycle);
  }
  public static Record getActiveRecord(IRequestCycle cycle) {
    return (Record )cycle.getAttribute(KEY);
  }
}

--
Author of a book for learning Tapestry (http://www.agileskills2.org/EWDT)


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


Re: getContainer()

Posted by Konstantin Ignatyev <kg...@yahoo.com>.
Very strange meaning then. Usually getContainer() or
something like that means exactly that what drgorb
expected. I would say that getContainer() name is
misleading and should be changed.

--- Mind Bridge <mi...@yahoo.com> wrote:

> I think you misunderstand the meaning of what
> getContainer() does. 
> Suppose page A includes component B in its template,
> and component B 
> includes component C in its template in return.
> C.getContainer() will 
> return the B component.
> 
> On the other hand, if page A includes both
> components B and C in its 
> template, and B only wraps C in A's template, then
> C.getContainer() will 
> return the A page.
> 
> In other words getContainer() does not point to an
> "enclosed by" 
> relationship, but a "part of" relationship.
> 
> drgorb wrote:
> > Hi,
> >
> > I try to use getContainer() inside a component to
> get at its parent, but the method allways returns
> the page object, no matter what.
> >
> > Are ther special conditions for this to work? Is
> there special configuration?
> >
> > In the following example, the IComponent parent is
> allways the Home page and never the enclosing tag.
> I've checked that with my eclipse debuger.
> >
> > HTML:
> > 	
> > 		
> > 			
> > 				
> > 				
> > 			
> > 			
> > 			
> > 			
> > 			
> > 		
> > 	
> >
> > The Label.java renderComponent method:
> > the class extends BaseComponent
> >
> >   @Override
> >   protected void renderComponent(IMarkupWriter
> writer, IRequestCycle cycle) {
> >     IComponent parent=getContainer();
> >     super.renderComponent(writer, cycle);
> >   }
> >
> >
> > -------------------- m2f --------------------
> >
> > Sent from www.TapestryForums.com
> >
> > Read this topic online here: <<topic_link>>
> >
> >
>
http://www.tapestryforums.com/viewtopic.php?p=14264#14264
> >
> > -------------------- m2f --------------------
> >
> >
> >
> >   
> 
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
> tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail:
> tapestry-user-help@jakarta.apache.org
> 
> 


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


Re: getContainer()

Posted by Mind Bridge <mi...@yahoo.com>.
I think you misunderstand the meaning of what getContainer() does. 
Suppose page A includes component B in its template, and component B 
includes component C in its template in return. C.getContainer() will 
return the B component.

On the other hand, if page A includes both components B and C in its 
template, and B only wraps C in A's template, then C.getContainer() will 
return the A page.

In other words getContainer() does not point to an "enclosed by" 
relationship, but a "part of" relationship.

drgorb wrote:
> Hi,
>
> I try to use getContainer() inside a component to get at its parent, but the method allways returns the page object, no matter what.
>
> Are ther special conditions for this to work? Is there special configuration?
>
> In the following example, the IComponent parent is allways the Home page and never the enclosing tag. I've checked that with my eclipse debuger.
>
> HTML:
> 	
> 		
> 			
> 				
> 				
> 			
> 			
> 			
> 			
> 			
> 		
> 	
>
> The Label.java renderComponent method:
> the class extends BaseComponent
>
>   @Override
>   protected void renderComponent(IMarkupWriter writer, IRequestCycle cycle) {
>     IComponent parent=getContainer();
>     super.renderComponent(writer, cycle);
>   }
>
>
> -------------------- m2f --------------------
>
> Sent from www.TapestryForums.com
>
> Read this topic online here: <<topic_link>>
>
> http://www.tapestryforums.com/viewtopic.php?p=14264#14264
>
> -------------------- m2f --------------------
>
>
>
>   

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