Embedding a Magritte component in another component

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Embedding a Magritte component in another component

squeakman
Greetings,

I have built a component called  "VeComponent", with an embedded
Magritte component. The code for rendering looks like:

VeComponent>>renderContentOn: html
    html render: self model asComponent addValidatedForm; yourself.
    html submitButton callback: [self answer: someValue];
         text: 'Done'


To test this code I call it from aWATask like this:

go>>
    returnValue := self call: aVeComponent.
    self halt.

This works, I get to the halt.


If I embed aVeComponent in another component then it appears that the
"self answer: someValue" in VeComponent>>renderContentOn: does not work.

What I observe is that clicking on the 'Done' button results in the
re-displaying of aVeComponent.

How is it that the code works when called from aWATask but it does not
work if it is contained in another component?

Can anyone explain what I am doing wrong?

Many Thanks,
Frank



_______________________________________________
SmallWiki, Magritte, Pier and Related Tools ...
https://www.iam.unibe.ch/mailman/listinfo/smallwiki
Reply | Threaded
Open this post in threaded view
|

Re: Embedding a Magritte component in another component

Lukas Renggli-2
There are several (Seaside related) problems with your code:

> I have built a component called  "VeComponent", with an embedded
> Magritte component. The code for rendering looks like:
>
> VeComponent>>renderContentOn: html
>    html render: self model asComponent addValidatedForm; yourself.
>    html submitButton callback: [self answer: someValue];
>         text: 'Done'

This instantiates a new component every-time the page is refreshed.  
You have to initialize the component outside the rendering method, for  
example when assigning the model to your component:

VeComponent>>model: aModel
    model := aModel.
    component := aModel asComponent addValidatedForm; yourself

VeComponent>>renderContentOn: html
    html render: component.
    html submitButton
         callback: [self answer: someValue];
         text: 'Done'

Furthermore you have to answer the component as a child:

VeComponent>>children
    ^ Array with: component

> If I embed aVeComponent in another component then it appears that the
> "self answer: someValue" in VeComponent>>renderContentOn: does not  
> work.

Initialize your component so that it passes the answer event to the  
outer component:

    component := aModel asComponent
       addValidatedForm;
       onAnswer: [ :value | self answer: value ];
       yourself

> What I observe is that clicking on the 'Done' button results in the
> re-displaying of aVeComponent.

That's the standard if no answer handler is defined.

Also note that a task runs as a loop. So when the go method finishes,  
it is automatically restarted.

Cheers,
Lukas

--
Lukas Renggli
http://www.lukas-renggli.ch

_______________________________________________
SmallWiki, Magritte, Pier and Related Tools ...
https://www.iam.unibe.ch/mailman/listinfo/smallwiki
Reply | Threaded
Open this post in threaded view
|

Re: Embedding a Magritte component in another component

cedreek
In reply to this post by squeakman
Hi



If I embed aVeComponent in another component then it appears that the
"self answer: someValue" in VeComponent>>renderContentOn: does not work.

What I observe is that clicking on the 'Done' button results in the
re-displaying of aVeComponent.

How is it that the code works when called from aWATask but it does not
work if it is contained in another component?

Can anyone explain what I am doing wrong?

You need to place your  call: in  a callback, not "directly" in renderContentOn:  like:

    html anchor
            callback: [self call: aVeComponent];
...

hth

cédrick


_______________________________________________
SmallWiki, Magritte, Pier and Related Tools ...
https://www.iam.unibe.ch/mailman/listinfo/smallwiki