Hi,
I have a PRViewComponent derived component in which, as part of the render method, I'd like to render another component defined elsewhere in my Pier structure. The code I've come up with so far is (simplified):
renderComponentOn: html | context component renderComponent | context := self context. component := context structure lookupPath: '/system/components/cloud'.
renderComponent := (context structure: component) command asComponent. html render: renderComponent Using PRContentsWidget as a template, I guess I also need to return the component in the #children method, which probably also means overriding the #onChangeContext: method to capture the context. I would then refactor the above code to cache the renderComponent in #onChangeContext:
Some questions: 1) Is there a simpler way of rendering another component defined elsewhere? 2) Do I need to create a new component each time onChangeContext: is called? Thanks Nick
_______________________________________________ Magritte, Pier and Related Tools ... https://www.iam.unibe.ch/mailman/listinfo/smallwiki |
Normally you should be able just to visit the other structure:
renderComponentOn: html html rendererInstance continue: (context structure lookupPath: '/system/components/cloud') in: self on: html Lukas On 13 April 2010 19:06, Nick Ager <[hidden email]> wrote: > Hi, > I have a PRViewComponent derived component in which, as part of the render > method, I'd like to render another component defined elsewhere in my Pier > structure. > The code I've come up with so far is (simplified): > renderComponentOn: html > | context component renderComponent | > context := self context. > component := context structure lookupPath: '/system/components/cloud'. > renderComponent := (context structure: component) command asComponent. > html render: renderComponent > Using PRContentsWidget as a template, I guess I also need to return the > component in the #children method, which probably also means overriding the > #onChangeContext: method to capture the context. I would then refactor the > above code to cache the renderComponent in #onChangeContext: > Some questions: > 1) Is there a simpler way of rendering another component defined elsewhere? > 2) Do I need to create a new component each time onChangeContext: is called? > Thanks > Nick > _______________________________________________ > Magritte, Pier and Related Tools ... > https://www.iam.unibe.ch/mailman/listinfo/smallwiki > -- Lukas Renggli www.lukas-renggli.ch _______________________________________________ Magritte, Pier and Related Tools ... https://www.iam.unibe.ch/mailman/listinfo/smallwiki |
Hi Lukas, Normally you should be able just to visit the other structure: Thanks works perfectly - I was sure there'd be a much neater method. Presumably though I still need to handle #children. Here's my first attempt:
onChangeContext: aContext aContext command isView ifTrue: [ | componentContext | componentContext := aContext structure: (aContext structure lookupPath: '/system/components/cloud').
component := componentContext command asComponent ] children ^ Array with: component Is there a neater way of implementing #children ?
Cheers Nick _______________________________________________ Magritte, Pier and Related Tools ... https://www.iam.unibe.ch/mailman/listinfo/smallwiki |
> Thanks works perfectly - I was sure there'd be a much neater method.
> Presumably though I still need to handle #children. Here's my first attempt: > onChangeContext: aContext > aContext command isView ifTrue: [ > | componentContext | > componentContext := aContext structure: (aContext structure > lookupPath: '/system/components/cloud'). > component := componentContext command asComponent > ] > children > ^ Array with: component > > Is there a neater way of implementing #children ? That doesn't quite work correctly, because #asComponent returns a new component each time. Better use #componentsIn: on the structure you are going to render. This answers the list of child components in a given context. Lukas -- Lukas Renggli www.lukas-renggli.ch _______________________________________________ Magritte, Pier and Related Tools ... https://www.iam.unibe.ch/mailman/listinfo/smallwiki |
Btw, all these tricks can be found in action in PRPierFrame, the root
component of Pier. Lukas On 14 April 2010 13:21, Lukas Renggli <[hidden email]> wrote: >> Thanks works perfectly - I was sure there'd be a much neater method. >> Presumably though I still need to handle #children. Here's my first attempt: >> onChangeContext: aContext >> aContext command isView ifTrue: [ >> | componentContext | >> componentContext := aContext structure: (aContext structure >> lookupPath: '/system/components/cloud'). >> component := componentContext command asComponent >> ] >> children >> ^ Array with: component >> >> Is there a neater way of implementing #children ? > > That doesn't quite work correctly, because #asComponent returns a new > component each time. > > Better use #componentsIn: on the structure you are going to render. > This answers the list of child components in a given context. > > Lukas > > -- > Lukas Renggli > www.lukas-renggli.ch > -- Lukas Renggli www.lukas-renggli.ch _______________________________________________ Magritte, Pier and Related Tools ... https://www.iam.unibe.ch/mailman/listinfo/smallwiki |
On 14 April 2010 12:21, Lukas Renggli <[hidden email]> wrote:
Btw, all these tricks can be found in action in PRPierFrame, the root Thanks Lukas, studying PRPierFrame makes much more sense. I was basing my code on PRContentsWidget Cheers Nick _______________________________________________ Magritte, Pier and Related Tools ... https://www.iam.unibe.ch/mailman/listinfo/smallwiki |
Free forum by Nabble | Edit this page |