Is it possible to create new comet-components on a page usin JS?

70 views
Skip to first unread message

Andreas Joseph Krogh

unread,
Feb 13, 2012, 3:37:24 AM2/13/12
to Lift
I have a comet-component and when receiving a special message (in
lowPriority) I'd like to install a new comet-component on the existing
page without reloading (and insert it using jQuery above the existing
comet-component). Is this possible?

Thanks.

--
Andreas Joseph Krogh<and...@officenet.no> - mob: +47 909 56 963
Senior Software Developer / CTO - OfficeNet AS - http://www.officenet.no
Public key: http://home.officenet.no/~andreak/public_key.asc

Jeppe Nejsum Madsen

unread,
Feb 13, 2012, 5:29:47 AM2/13/12
to lif...@googlegroups.com
Andreas Joseph Krogh <and...@officenet.no> writes:

> I have a comet-component and when receiving a special message (in
> lowPriority) I'd like to install a new comet-component on the existing
> page without reloading (and insert it using jQuery above the existing
> comet-component). Is this possible?

I haven't tried, but how about just SetHtml("myId", S.eval(<lift:comet>...</lift:comet>))

/Jeppe

Andreas Joseph Krogh

unread,
Feb 13, 2012, 6:17:35 AM2/13/12
to lif...@googlegroups.com

I see that comet-actors spits out markup in the initial page-rendering
which declares JS-functions in the global-scope like:

function F421886944904COY31Q(obj) {liftAjax.lift_ajaxHandler('F421886944904COY31Q='+ encodeURIComponent(JSON.stringify(obj)), null,null);}
var destroy_F421886944901IWNRAP = function() {}


, which doesn't work using JS (AJAX) afaik. That's why I didn't bother
to try what you suggested, which I assume will fail according to my
knowledge of how JS works.

If my assumptions are correct the situation might be improved tho.
Instead of declaring these functions/variables in the globa-scope we
could have a Lift.Comet JS-object and we could register/de-register
JS-functions in that object more dynamically and make installing new
CometActors work using AJAX.

Franz Bettag

unread,
Feb 13, 2012, 6:41:43 AM2/13/12
to lif...@googlegroups.com
i could see this getting messy, have you thought about a REST-comet actor which your JS uses? I have a good use case for that, also in David's github repo you will find the london_calling project, there is something like it. not sure if it fits your case, just an idea :)

Andreas Joseph Krogh

unread,
Feb 13, 2012, 6:48:01 AM2/13/12
to lif...@googlegroups.com
On 02/13/2012 12:41 PM, Franz Bettag wrote:
> i could see this getting messy, have you thought about a REST-comet
> actor which your JS uses?

Can you elaborate how such a REST-comet-actor behaves and is configured?

> I have a good use case for that, also in David's github repo you will
> find the london_calling project, there is something like it. not sure
> if it fits your case, just an idea :)

Without new ideas the world would stop:-)

Franz Bettag

unread,
Feb 13, 2012, 6:59:38 AM2/13/12
to lif...@googlegroups.com
https://github.com/dpp/london_calling_october/blob/master/src/main/scala/code/lib/StatelessContentThing.scala

this is the idea, but this example is stateless. (i also only have stateless in use for that purpose currently)

sessionless long-polling will be my new golden horse :P

David Pollak

unread,
Feb 13, 2012, 9:39:30 AM2/13/12
to lif...@googlegroups.com
Andreas,

Lift doesn't allow adding a CometActor/Comet Component to an already rendered page.  There's an open ticket for the issue..

Thanks,

David

--
Lift, the simply functional web framework: http://liftweb.net
Code: http://github.com/lift
Discussion: http://groups.google.com/group/liftweb
Stuck? Help us help you: https://www.assembla.com/wiki/show/liftweb/Posting_example_code



--
Visi.Pro, Cloud Computing for the Rest of Us http://visi.pro
Lift, the simply functional web framework http://liftweb.net


Andreas Joseph Krogh

unread,
Feb 13, 2012, 9:44:13 AM2/13/12
to lif...@googlegroups.com
On 02/13/2012 03:39 PM, David Pollak wrote:
> Andreas,
>
> Lift doesn't allow adding a CometActor/Comet Component to an already
> rendered page. There's an open ticket for the issue..

Can you point me to the relevant code so I can get a grip on how
difficult it is to implement that ticket (#933)?

Donald McLean

unread,
Feb 13, 2012, 11:57:16 AM2/13/12
to lif...@googlegroups.com
Currently, if you are going to use comet, you have to put the comet
actor on the page during the initial rendering. This is one of the
comet issues that is discussed on one of the wiki pages.

I have a system with dynamic content panels. To make them work, the
area where the panels go is a comet actor that is part of the original
page. Inside that page, I have a block that I regularly swap out and I
have a "CometHelper" class that is affiliated with an HTML file. The
html file is loaded with an "embed" tag in a comet update. The
CometHelper class is created using reflection.

When the panel needs an update, it sends a message to the CometActor
which calls the CometHelper function that generates the actual update.

It might not be quite as pretty as being able to dynamically load
CometActors but it works just fine.

Donald

David Pollak

unread,
Feb 13, 2012, 1:09:53 PM2/13/12
to lif...@googlegroups.com
On Mon, Feb 13, 2012 at 6:44 AM, Andreas Joseph Krogh <and...@officenet.no> wrote:
On 02/13/2012 03:39 PM, David Pollak wrote:
Andreas,

Lift doesn't allow adding a CometActor/Comet Component to an already rendered page.  There's an open ticket for the issue..

Can you point me to the relevant code so I can get a grip on how difficult it is to implement that ticket (#933)?

Some of the code is in LiftMerge.scala (the merge method) and some of the code is in ScriptRenderer.scala in the cometScript method.

The key is to update the list of CometActors to watch.
 


Thanks.

--
Andreas Joseph Krogh<and...@officenet.no>  - mob: +47 909 56 963
Senior Software Developer / CTO - OfficeNet AS - http://www.officenet.no
Public key: http://home.officenet.no/~andreak/public_key.asc

--
Lift, the simply functional web framework: http://liftweb.net
Code: http://github.com/lift
Discussion: http://groups.google.com/group/liftweb
Stuck? Help us help you: https://www.assembla.com/wiki/show/liftweb/Posting_example_code

Andreas Joseph Krogh

unread,
Feb 13, 2012, 4:56:41 PM2/13/12
to lif...@googlegroups.com
On 02/13/2012 07:09 PM, David Pollak wrote:


On Mon, Feb 13, 2012 at 6:44 AM, Andreas Joseph Krogh <and...@officenet.no> wrote:
On 02/13/2012 03:39 PM, David Pollak wrote:
Andreas,

Lift doesn't allow adding a CometActor/Comet Component to an already rendered page.  There's an open ticket for the issue..

Can you point me to the relevant code so I can get a grip on how difficult it is to implement that ticket (#933)?

Some of the code is in LiftMerge.scala (the merge method) and some of the code is in ScriptRenderer.scala in the cometScript method.

The key is to update the list of CometActors to watch.

Thanks, I'll have a look.
Reply all
Reply to author
Forward
0 new messages