updating the contents of a div as a side effect of a liveCallback..

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

updating the contents of a div as a side effect of a liveCallback..

Rick Flower
It seems to be that you're not able to do this directly care of a
message I saw from Michel a while back, but I can't find it now.. and it
also seems to be I saw code that did something like this, but I'm having
  a brain fart and can't seem to locate anything relevant..

Anyway, I've got div mixed in with other stuff on a page and when a
button is pressed I get a liveCallback block running.. I was hoping that
I could update the contents of the div at that point but Seaside is
complaining (likely because it's not allowed)..  So, if this is not
allowed in that manner, I'm sure someone else has written code that does
the same sort of stuff -- how did you achieve it?  Or perhaps my code is
just naughty..

As usual-- many thanks in advance!
_______________________________________________
Seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

RE: updating the contents of a div as a side effect of aliveCallback..

Ramon Leon-5
> It seems to be that you're not able to do this directly care
> of a message I saw from Michel a while back, but I can't find
> it now.. and it also seems to be I saw code that did
> something like this, but I'm having
>   a brain fart and can't seem to locate anything relevant..
>
> Anyway, I've got div mixed in with other stuff on a page and
> when a button is pressed I get a liveCallback block running..
> I was hoping that I could update the contents of the div at
> that point but Seaside is complaining (likely because it's
> not allowed)..  So, if this is not allowed in that manner,
> I'm sure someone else has written code that does the same
> sort of stuff -- how did you achieve it?  Or perhaps my code
> is just naughty..
>
> As usual-- many thanks in advance!

I'd help you out, but frankly I don't use SeasideAsync, I think
Scriptaculous is a much better and more composeable framework for doing this
sort of thing.  IMHO using SeasideAsync is like using the old renderer, a no
no.  You should consider switching.

Ramon Leon
http://onsmalltalk.com 

_______________________________________________
Seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

Re: updating the contents of a div as a side effect of aliveCallback..

Rick Flower
Ramon Leon wrote:
  [ ... ]
> I'd help you out, but frankly I don't use SeasideAsync, I think
> Scriptaculous is a much better and more composeable framework for doing this
> sort of thing.  IMHO using SeasideAsync is like using the old renderer, a no
> no.  You should consider switching.

Ok Ramon..  You're begging my next question.. What sort of stuff should
need to be changed IF I switched?  I'm assuming at least the following :

1) #rendererClass currently returns ^Seaside.WAAsyncRenderCanvas
    but I gather it should be WARenderCanvas for Scriptaculous?

2) Base component should be WAComponent instead of the Async version
    (WAAsyncComponent)

3) Change instances of html blah ... liveCallback: [] to something using
    onClick:[] instead?  I gather I need to specify a "control & model
    for each item -- not sure what those do exactly yet..

Did I miss anything? If I did switch now it would be fairly trivial
assuming the Scriptaculous stuff has something like the liveCallbacks.

So, IF I switched, how *could* I update a div within the current page
when a particular event is triggered?

Thanks!


_______________________________________________
Seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

Re: updating the contents of a div as a side effect of a liveCallback..

Michel Bany-3
In reply to this post by Rick Flower

> ... Seaside is complaining (likely because it's not allowed)..
Can you be more specific ?
Are you able to create a small example that produce the Seaside complaint ?
Michel.

_______________________________________________
Seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

Re: updating the contents of a div as a side effect of a liveCallback..

Rick Flower
Michel Bany wrote:
>
>> ... Seaside is complaining (likely because it's not allowed)..
> Can you be more specific ?
> Are you able to create a small example that produce the Seaside complaint ?

Michel -- It might be something I'm doing wrong, but I thought I saw
test code in the Async package that is more or less doing what I'm
doing.. I've got a submit button with the liveCallback (the new stuff
that you added the other day) that looks like the following :

html div id: #blah with: [ html submitButton liveCallback: [:r | self
renderCartContents: self on: r]; text: 'Add to Cart'].

Down in >>renderCartContents I've got the following :

 >>renderCartContents: dummy on: html
html text: 'blah'

When it comes time to do the liveCallback (by pressing the submit
button), I get the follow dialog box from Seaside :

No replacement and no script evaluated, probable bug in your callback code.

See below the response produced by the callback code.

<?xml version="1.0" encoding="utf-8"?><body>blah</body>
_______________________________________________
Seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

RE: updating the contents of a div as a side effect ofaliveCallback..

Ramon Leon-5
In reply to this post by Rick Flower
> 1) #rendererClass currently returns ^Seaside.WAAsyncRenderCanvas
>     but I gather it should be WARenderCanvas for Scriptaculous?

Yup, and in current version, this is already the default, so you don't have
to do anything.

> 2) Base component should be WAComponent instead of the Async version
>     (WAAsyncComponent)

Yup.

> 3) Change instances of html blah ... liveCallback: [] to
> something using
>     onClick:[] instead?  I gather I need to specify a "control & model
>     for each item -- not sure what those do exactly yet..
>
> Did I miss anything? If I did switch now it would be fairly
> trivial assuming the Scriptaculous stuff has something like
> the liveCallbacks.

Scriptaculous should be able to easily do anything liveCallbacks are doing
and then some.

> So, IF I switched, how *could* I update a div within the
> current page when a particular event is triggered?
>
> Thanks!

Here's the pattern...

html anyElement
    onClick: (html updater id: #divYouWantToUpdate;
        callback:[:ajax | self renderDivYouWantToUpdateAgainOn: ajax ]);
with: 'Bla Bla'

This is why it's important to factor the code well.  Ideally, any part of
the page you want to ajax update, has it's own rendering method, so you can
call it normally on the server side for the first page render, and then pass
the ajax canvas through the same method to live update that part of the page
whenever you like on whatever javascript event you like.

Ramon Leon
http://onsmalltalk.com 

_______________________________________________
Seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

Re: updating the contents of a div as a side effect ofaliveCallback..

Rick Flower
Ramon Leon wrote:

> Here's the pattern...
>
> html anyElement
>     onClick: (html updater id: #divYouWantToUpdate;
>         callback:[:ajax | self renderDivYouWantToUpdateAgainOn: ajax ]);
> with: 'Bla Bla'
>
> This is why it's important to factor the code well.  Ideally, any part of
> the page you want to ajax update, has it's own rendering method, so you can
> call it normally on the server side for the first page render, and then pass
> the ajax canvas through the same method to live update that part of the page
> whenever you like on whatever javascript event you like.

Thanks Ramon.. I'll keep that in the back of my head if I decide to move
over to Scriptaculous from the Async side...  In the meantime I'll wait
to see what Michel says about my issue -- perhaps it's a bug since the
liveCallbacks were added to the submitButton just the other day..


_______________________________________________
Seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

RE: updating the contents of a div as a side effect ofaliveCallback..

Ron Teitelbaum
In reply to this post by Ramon Leon-5
Ramon, Michel,

I really like the Async code, I'm using it and it works great.  I have them
both loaded and I'm not having any trouble with it so I may use pieces of
both.  Also I have to say that having Michel as a resource has been
terrific!  

Thanks Michel!

Ron Teitelbaum

> -----Original Message-----
> From: Ramon Leon
> Sent: Wednesday, January 31, 2007 1:47 PM
>
> > It seems to be that you're not able to do this directly care
> > of a message I saw from Michel a while back, but I can't find
> > it now.. and it also seems to be I saw code that did
> > something like this, but I'm having
> >   a brain fart and can't seem to locate anything relevant..
> >
> > Anyway, I've got div mixed in with other stuff on a page and
> > when a button is pressed I get a liveCallback block running..
> > I was hoping that I could update the contents of the div at
> > that point but Seaside is complaining (likely because it's
> > not allowed)..  So, if this is not allowed in that manner,
> > I'm sure someone else has written code that does the same
> > sort of stuff -- how did you achieve it?  Or perhaps my code
> > is just naughty..
> >
> > As usual-- many thanks in advance!
>
> I'd help you out, but frankly I don't use SeasideAsync, I think
> Scriptaculous is a much better and more composeable framework for doing
> this
> sort of thing.  IMHO using SeasideAsync is like using the old renderer, a
> no
> no.  You should consider switching.
>
> Ramon Leon
> http://onsmalltalk.com
>
> _______________________________________________
> Seaside mailing list
> [hidden email]
> http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside


_______________________________________________
Seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

Re: updating the contents of a div as a side effect ofaliveCallback..

Rick Flower
Ron Teitelbaum wrote:
> Ramon, Michel,
>
> I really like the Async code, I'm using it and it works great.  I have them
> both loaded and I'm not having any trouble with it so I may use pieces of
> both.  Also I have to say that having Michel as a resource has been
> terrific!  

I'll have to admit that after looking at the code for the Scriptaculous
examples, I find the SeasideAsync stuff much easier to follow.. I guess
it depends on what you're after.. In my case, I don't need drag-n-drop
or some of the other nifty features of Scriptaculous -- at least for
today.. Not sure if that would change with this particular web-app or
not.. I still need to do more homework to make sure I'm heading down the
right path.

Either way, both  are great pieces of software!
_______________________________________________
Seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

Re: updating the contents of a div as a side effect of a liveCallback..

Rick Flower
In reply to this post by Rick Flower
Rick Flower wrote:

> Michel Bany wrote:
>>
>>> ... Seaside is complaining (likely because it's not allowed)..
>> Can you be more specific ?
>> Are you able to create a small example that produce the Seaside
>> complaint ?
>
> Michel -- It might be something I'm doing wrong, but I thought I saw
> test code in the Async package that is more or less doing what I'm
> doing.. I've got a submit button with the liveCallback (the new stuff
> that you added the other day) that looks like the following :
>
> html div id: #blah with: [ html submitButton liveCallback: [:r | self
> renderCartContents: self on: r]; text: 'Add to Cart'].
>
> Down in >>renderCartContents I've got the following :
>
> >>renderCartContents: dummy on: html
> html text: 'blah'
>
> When it comes time to do the liveCallback (by pressing the submit
> button), I get the follow dialog box from Seaside :
>
> No replacement and no script evaluated, probable bug in your callback
> code.
>
> See below the response produced by the callback code.
>
> <?xml version="1.0" encoding="utf-8"?><body>blah</body>
Ok.. I changed my test code in the liveCallback from that shown above to
the following and my problems disappeared.. It must be my
misunderstanding of ST I guess..

liveCallback: [:h | h span id: #cart_contents; with: [self
renderCartContents: self on: h ]];

I guess it needs to write into a span...

-- Rick
_______________________________________________
Seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

Re: updating the contents of a div as a side effect of a liveCallback..

Michel Bany-3
Rick Flower a écrit :

> Rick Flower wrote:
>> Michel Bany wrote:
>>>
>>>> ... Seaside is complaining (likely because it's not allowed)..
>>> Can you be more specific ?
>>> Are you able to create a small example that produce the Seaside
>>> complaint ?
>>
>> Michel -- It might be something I'm doing wrong, but I thought I saw
>> test code in the Async package that is more or less doing what I'm
>> doing.. I've got a submit button with the liveCallback (the new stuff
>> that you added the other day) that looks like the following :
>>
>> html div id: #blah with: [ html submitButton liveCallback: [:r | self
>> renderCartContents: self on: r]; text: 'Add to Cart'].
>>
>> Down in >>renderCartContents I've got the following :
>>
>> >>renderCartContents: dummy on: html
>> html text: 'blah'
>>
>> When it comes time to do the liveCallback (by pressing the submit
>> button), I get the follow dialog box from Seaside :
>>
>> No replacement and no script evaluated, probable bug in your callback
>> code.
>>
>> See below the response produced by the callback code.
>>
>> <?xml version="1.0" encoding="utf-8"?><body>blah</body>
> Ok.. I changed my test code in the liveCallback from that shown above
> to the following and my problems disappeared.. It must be my
> misunderstanding of ST I guess..
>
> liveCallback: [:h | h span id: #cart_contents; with: [self
> renderCartContents: self on: h ]];
>
> I guess it needs to write into a span...
Now I see what's wrong.

SeasideAsync identifies the is only capable of updating the page,
it does not add to it. You should look a bit closer at the test code
in #renderButtonOn:. You will see that the span area with id
'timestamp-button' is defined in the regular rendering code
and updated by thelive callback.

For updating a particular area of the page you need to designate
what element in the page is to be updated using the id attribute.
renderCartContents: dummy on: html
    html div id: #cart; class: #cart; with: [ ... ].

You also need a place holder with the same id so that SeasideAsync
knows what area of the page will be updated. The place holder may
be completely empty, it may show some initial value or it may be hidden.
    html submitButton liveCallback: [:r | self renderCartContents: self
on: r]; text: 'Add to Cart'].
    ...
    html div id: #cart; with: String new.
or
    html div id: #cart; with: 'Your cart is empty'.
or
    html div id: #cart; class: #hidden; with: 'Place holder for the cart'.

HTH
Michel.





_______________________________________________
Seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

RE: updating the contents of a div as a side effect ofa liveCallback..

Bany, Michel
> SeasideAsync identifies the is only capable of updating the
> page, it does not add to it.

Oops, I meant the following

SeasideAsync is only capable of updating the page, it does not add to
it.
_______________________________________________
Seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

Re: updating the contents of a div as a side effect of a liveCallback..

Rick Flower
In reply to this post by Michel Bany-3
Michel Bany wrote:

> SeasideAsync identifies the is only capable of updating the page,
> it does not add to it. You should look a bit closer at the test code
> in #renderButtonOn:. You will see that the span area with id
> 'timestamp-button' is defined in the regular rendering code
> and updated by thelive callback.

Thanks Michel -- this was my problem obviously.. I had only written
that code very hastily to just ensure something was happening when the
liveCallback was invoked.. I didn't even think that it would matter if I
did or didn't specify a div/span/class ID.. Anyway, all appears to be
well again.. Thanks for the clarification!

_______________________________________________
Seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

Re: updating the contents of a div as a side effect of a liveCallback..

Michel Bany

>> SeasideAsync identifies the is only capable of updating the page,
>> it does not add to it. You should look a bit closer at the test code
>> in #renderButtonOn:. You will see that the span area with id
>> 'timestamp-button' is defined in the regular rendering code
>> and updated by thelive callback.
>
> Thanks Michel -- this was my problem obviously.. I had only written
> that code very hastily to just ensure something was happening when  
> the liveCallback was invoked.. I didn't even think that it would  
> matter if I did or didn't specify a div/span/class ID.. Anyway, all  
> appears to be well again.. Thanks for the clarification!
>

I see. You were probably confused with the new dialog box.

This new dialog box is displayed by the SeasideAsync javascript when
the live callback is unproductive, this happens when the javascript does
not find any matching id in the page. In previous versions of  
SeasideAsync
the whole page was replaced with the output of the live callback.
This was even more confusing. With the new dialog box, things are made
clearer and the actual xml output from the live callback is shown to  
help
you with the debugging.

Good to hear that all is well again for you.
Michel.
_______________________________________________
Seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside