Using same comet snippet on two areas of the same page - not as expected

131 views
Skip to first unread message

Diego Medina

unread,
Feb 1, 2012, 12:10:01 AM2/1/12
to Lift
Hi,

I have this one page that has about 20 fields, they all show
information about a product, so they are all related.

In my html file, I have two main divs

<div main info ... cometClass></div>
<div secondary info ... cometClass></div>

...

My render method has css rules to match the span tags from both, main
and secondary sections. But when I run my unit test using S.template
or even when I visit the page on the browser, what ends up happening
is that the html of the main info section is shown on both, the main
and secondary div.

I know I could split my render into two methods, but I was wondering
if I could keep them all in one, because while looking at the scala
code, it does not make much sense to separate them, I only separate
them because of UI requirements.

Thanks

Diego

--
Diego Medina
Lift/Scala Developer
di...@fmpwizard.com
http://www.fmpwizard.com

Sofoklis Papasofokli

unread,
Feb 1, 2012, 1:27:18 AM2/1/12
to lif...@googlegroups.com
Hi Diego,

I think if you simply put a parent span for the 2 divs you should be ok

<span class="lift...">
<div>...</div>
<div>...</div>
</span>


--
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



--
Sofoklis

Jeppe Nejsum Madsen

unread,
Feb 1, 2012, 5:17:51 AM2/1/12
to lif...@googlegroups.com
Diego Medina <di...@fmpwizard.com> writes:

> Hi,
>
> I have this one page that has about 20 fields, they all show
> information about a product, so they are all related.
>
> In my html file, I have two main divs
>
> <div main info ... cometClass></div>
> <div secondary info ... cometClass></div>
>
> ...
>
> My render method has css rules to match the span tags from both, main
> and secondary sections. But when I run my unit test using S.template
> or even when I visit the page on the browser, what ends up happening
> is that the html of the main info section is shown on both, the main
> and secondary div.
>
> I know I could split my render into two methods, but I was wondering
> if I could keep them all in one, because while looking at the scala
> code, it does not make much sense to separate them, I only separate
> them because of UI requirements.

You know the drill, provide example code :-)

Is it the same if you remove the comet stuff?

/Jeppe

Diego Medina

unread,
Feb 1, 2012, 12:04:14 PM2/1/12
to lif...@googlegroups.com
>
> You know the drill, provide example code :-)

jeje, I should know better, I'll put one together and post back

>
> Is it the same if you remove the comet stuff?

you mean use a regular snippet? I did not try, but will try and let you know

Thanks

Diego

>
> /Jeppe


>
> --
> 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

--

David Pollak

unread,
Feb 1, 2012, 12:22:39 PM2/1/12
to lif...@googlegroups.com
It's not possible to use the same CometActor instance in more than 1 place on a page.

I look forward to your code to see what's going on.  I'll prioritize it on my Lift Monday (if not before.)
Visi.Pro, Cloud Computing for the Rest of Us http://visi.pro
Lift, the simply functional web framework http://liftweb.net

Diego Medina

unread,
Feb 1, 2012, 9:41:22 PM2/1/12
to lif...@googlegroups.com
On Wed, Feb 1, 2012 at 12:22 PM, David Pollak
<feeder.of...@gmail.com> wrote:
> It's not possible to use the same CometActor instance in more than 1 place
> on a page.
>
> I look forward to your code to see what's going on.  I'll prioritize it on
> my Lift Monday (if not before.)

Thanks David, I'm still trying to reproduce it on a smaller sample. Of
course it works just fine on the demo (the initial render, I did not
try to send a partialUpdate )
I did notice that even on my real application, the only way to trigger
this is by first running a unit test that tests this snippet using
testS {} and then start jetty.
I I first start sbt, then jetty, the page renders normally.

I'll keep working on this and post back as soon as I know more (and
hopefully can get a small sample showing what I see)

Thanks

Diego

Diego Medina

unread,
Feb 3, 2012, 12:06:21 AM2/3/12
to lif...@googlegroups.com
After trying for a long time to reproduce it, I decided it was going
to be a better idea to just split my comet class into smaller ones.
Thanks

Diego

Diego Medina

unread,
Feb 3, 2012, 12:46:40 AM2/3/12
to lif...@googlegroups.com
Ah, after I sent this email I figured out why the demo was not doing
the same thing.

This only happens in run.mode=test :)

Full project using sbt 0.7.7 including sbt launcher and everything you
need it at
https://github.com/fmpwizard/single_comet_two_div

Thanks

Diego

David Pollak

unread,
Feb 6, 2012, 3:30:58 PM2/6/12
to lif...@googlegroups.com
On Thu, Feb 2, 2012 at 9:46 PM, Diego Medina <di...@fmpwizard.com> wrote:
Ah, after I sent this email I figured out why the demo was not doing
the same thing.

This only happens in run.mode=test :)

Full project using sbt 0.7.7 including sbt launcher and everything you
need it at
https://github.com/fmpwizard/single_comet_two_div


You cannot have two instances of the same Comet component on the same page.  Each comet component must be unique.  You have  <lift:comet type="helloworld" name="Other"> on the index.html page twice.  That breaks the Comet paradigm and will not work.

The reason is that the CometActor exists outside the context of a given page.  In order to draw itself, the CometActor is given a DOM (NodeSeq) that it re-uses.  In dev mode, the DOM is passed each time the CometActor is encountered on a page.  In non-dev-mode, the DOM is presented to the CometActor the first time it is encountered and the CometActor caches the DOM.

Hope this helps.

Diego Medina

unread,
Feb 6, 2012, 4:07:40 PM2/6/12
to lif...@googlegroups.com

Diego
Sent from my android cell


On Feb 6, 2012 3:31 PM, "David Pollak" <feeder.of...@gmail.com> wrote:
>
>
>
> On Thu, Feb 2, 2012 at 9:46 PM, Diego Medina <di...@fmpwizard.com> wrote:
>>
>> Ah, after I sent this email I figured out why the demo was not doing
>> the same thing.
>>
>> This only happens in run.mode=test :)
>>
>> Full project using sbt 0.7.7 including sbt launcher and everything you
>> need it at
>> https://github.com/fmpwizard/single_comet_two_div
>>
>
> You cannot have two instances of the same Comet component on the same page.  Each comet component must be unique.  You have  <lift:comet type="helloworld" name="Other"> on the index.html page twice.  That breaks the Comet paradigm and will not work.
>
> The reason is that the CometActor exists outside the context of a given page.  In order to draw itself, the CometActor is given a DOM (NodeSeq) that it re-uses.  In dev mode, the DOM is passed each time the CometActor is encountered on a page.  In non-dev-mode, the DOM is presented to the CometActor the first time it is encountered and the CometActor caches the DOM.
>
> Hope this helps.
>  

Yes it does  and I'm actually happier now that I  split it into several comet actors.

Thanks!

Diego

Diego Medina

unread,
Feb 7, 2012, 12:19:13 AM2/7/12
to lif...@googlegroups.com
> it re-uses.  In dev mode, the DOM is passed each time the CometActor is
> encountered on a page.  In non-dev-mode, the DOM is presented to the
> CometActor the first time it is encountered and the CometActor caches the
> DOM.

I was thinking about this a bit more today and I wonder if it would
make sense to change the dev-mode behavior . I mean, just looking at
this aspect of dev-mode, it would seem better to use the cache NodeSeq
on all modes. What do you think?

Thanks

Diego

Franz Bettag

unread,
Feb 7, 2012, 12:31:34 AM2/7/12
to lif...@googlegroups.com
diego +1, make it the same over all modes. saves issues/confusion.

To help your case (i didnt read everything), have you tried subclassing your CometActor? not sure it works, but give it a try.

David Pollak

unread,
Feb 7, 2012, 12:37:17 AM2/7/12
to lif...@googlegroups.com
-1 the dev mode behavior allows you to reload a page with a new template and see the new template reflected in the comet actor. If the caching behavior was in dev mode you'd have to restart the app each time you made a template change.

Diego Medina

unread,
Feb 7, 2012, 12:40:23 AM2/7/12
to lif...@googlegroups.com

Diego
Sent from my android cell

On Feb 7, 2012 12:37 AM, "David Pollak" <feeder.of...@gmail.com> wrote:
>
> -1 the dev mode behavior allows you to reload a page with a new template and see the new template reflected in the comet actor. If the caching behavior was in dev mode you'd have to restart the app each time you made a template change.

Ah,I see, I thought there was a good reason.

Thanks

Diego Medina

unread,
Feb 7, 2012, 12:41:44 AM2/7/12
to lif...@googlegroups.com

Diego
Sent from my android cell

On Feb 7, 2012 12:31 AM, "Franz Bettag" <fr...@bett.ag> wrote:
>
> diego +1, make it the same over all modes. saves issues/confusion.
>
> To help your case (i didnt read everything), have you tried subclassing your CometActor? not sure it works, but give it a try.
>

I went ahead and now I use two different cometactors and all us well, thanks

Diego

Franz Bettag

unread,
Feb 7, 2012, 12:53:00 AM2/7/12
to lif...@googlegroups.com
also david is right, didnt think about that. -1

sorry
Reply all
Reply to author
Forward
0 new messages