Lift comet do not render when the first time of loading page

101 views
Skip to first unread message

Chenguang He

unread,
Oct 7, 2012, 6:24:14 PM10/7/12
to lif...@googlegroups.com
Hey guys,
I have a page, that want to render every 10sec. i use ActorPing.schedule, which same to the demo in lift website.
However, i found that, when use load page in the first cycle of 10sec, the page will not be rendered by comet. And, everything work fine, after 10sec.

Here is the code:



package code.comet


class hotjobs extends CometActor {
private var jobs:List[Jobs] = Nil

def render = "#hot" #> <table class="table table-striped">{jobs.flatMap(jobsExtrator _)}</table>

def jobsExtrator(j:Jobs):NodeSeq=
<tr>
<td>{modifyDate(j.createdAt.toString())}</td>
<td>{j.title}</td>
<td>{j.companyName}</td>
<td>{j.location}</td>
<td style="text-align: right;"><button type="button" datatoggle="button" onClick={JsCmds.RedirectTo("/jobDetail.html?jobid="+j.id)}>立即申请</button></td>
</tr>

def modifyDate(s:String):String={
val b = s.split(" ")
return b(1)+"-"+b(2)+"-"+b(3)
}


ActorPing.schedule(this, Message, 10000L)

override def lowPriority = {
case Message => {
reRender()
jobs = Jobs.findJobsinTop
ActorPing.schedule(this, Message, 10000L)
}
}
}
case object Message

Chenguang He




David Pollak

unread,
Oct 7, 2012, 6:33:21 PM10/7/12
to lif...@googlegroups.com
  1. You should not use a timed update. You should update the CometActor on state change on the server (time is not state change)
  2. If you post a reproducible example, we can help you.





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






--
Telegram, Simply Beautiful CMS https://telegr.am
Lift, the simply functional web framework http://liftweb.net


Chenguang He

unread,
Oct 7, 2012, 7:16:09 PM10/7/12
to lif...@googlegroups.com
Hey David,
I can not change the comet to state-based update. Is there any way that use time-based update to make the page work in first time loading ?

Thank you 
Chenguang He



Diego Medina

unread,
Oct 7, 2012, 11:04:00 PM10/7/12
to lif...@googlegroups.com
Hi Chenguang,

The whole point of using Comet is to avoid timed refreshes, if all you
want is to refresh the whole page, you may as well just use Javascript
to reload the complete page (but users will hate this).
Working with Actors and comet could be a bit different than what you
are used to, but once we see a sample application that shows what you
are trying to do, we can help you see how to avoid a timed refresh.
But in any case, see David's second bullet point, which refers to
https://www.assembla.com/wiki/show/liftweb/Posting_example_code

Thanks

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

Chenguang He

unread,
Oct 8, 2012, 12:10:21 AM10/8/12
to lif...@googlegroups.com
Thank you, maybe there are something misunderstand.
The client gave us a API which can get the jobs from some website, we also have feature that allows users to post jobs in our website.
If i do this thing in event-base, which mean, the jobs list refresh every time the user post a jobs in our website, then how to show users the jobs that i get from API,?
So the only way i think, it is a time-based refresh.


Chenguang He



Andreas Joseph Krogh

unread,
Oct 8, 2012, 4:05:45 AM10/8/12
to lif...@googlegroups.com
On 10/08/2012 01:16 AM, Chenguang He wrote:
> Hey David,
> I can not change the comet to state-based update. Is there any way
> that use time-based update to make the page work in first time loading ?

Is your comet-actor not registered with any server (ListenerManager) ?
Remember that if your actor hasn't gotten any messages when render() is
called it will not show anything as "jobs" will be Nil
If you register it with a server (ListenerManager) then its
createUpdate() will send the initial message to your comet-actor and you
can then react on that message to render the initial content. Further
pings should ping the actor-server (not comet-actor) which again calls
updateListeners(message) which will take care of updating your
comet-component.

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

Chenguang He

unread,
Oct 8, 2012, 4:58:12 AM10/8/12
to lif...@googlegroups.com
Yea, you are right.
I should register to a server, and everything work fine now
Thanks

Chenguang He




David Pollak

unread,
Oct 8, 2012, 10:52:16 AM10/8/12
to lif...@googlegroups.com
To reinforce what Andreas and Diego said:

If there's an external resource that you have to poll, that's not the job of your CometActor because you don't want 1,000 users polling the same resource. That's the job of a single entity that polls the external resource. That polling can be timed or whatever. When that entity has a state change, it notifies all the listeners with new state/state delta/both. Then the listeners "do the right thing" with the update.
--
Telegram, Simply Beautiful CMS https://telegr.am
Lift, the simply functional web framework http://liftweb.net

Chenguang He

unread,
Oct 8, 2012, 3:56:23 PM10/8/12
to lif...@googlegroups.com
Yea, i got it. Thank you David


Chenguang He
Reply all
Reply to author
Forward
0 new messages