Hi Marius,
 Thanks for the quick update.
The xhtml returned from the listFilesInDir() is actually sent as a
message to a display CometActor which renders the xhtml it receives
within a specific <div> tag.
So in essence we have these multiple feature threads running(the one
in question is intended to be a local file manager feature) which
generates xhtml for different functions which are then sent to this
one display CometActor which displays it.
So we intend to handle multi-feature tasking by running just the one
CometActor and not multiples of them which obviously is a problem for
lift(since the max no. of CometActors in a page is 2).

But back to your explanation of the S context getting lost, I think I
understand what you mean regarding the session context. But does it
also apply for SHtml generator methods?? I mean, does SHtml generator
methods depend on the state of the session??
Another question I have is - even if SHtml generator methods fail to
co-relate the session, shouldn't SHtml generator methods return?? or
throw an exception?
I don't know if you happened to use the exact same function in a
LiftActor object or not, but if you do that you'll see that the
function just doesn't return.

Also, I don't intend to maintain state preservation. I just want to
create a list of <a href> tags for all files which when clicked should
make an Ajax call to a specific function in the LiftActor thread which
processes the selection. Could you suggest some alternative way I
could go about this with the current architecture(1 comet actor for
display and individual feature-specific LiftActors sending xhtml to
CometActor for rendering)??

Thanks,
Soumik

On Feb 16, 1:16 pm, Marius <[email protected]> wrote:
> Well so you're using it from your own actor. I would not recommend
> this due to state preservation. I mean S context is very likely lost
> because your LiftActor is running on a different thread. What you need
> is to pass the LiftSession instance to your LiftActor say using some
> distinct message like:
>
> case class Init(session: LiftSession)
>
> then in your messageHandler
>
>  protected def messageHandler = {
>        case FileManagerMsg(someMsg) =>
>        {
>          S.initIfNotInitted(session) {
>             var fileList = listFilesInDir("/Users/soumik/Movies/")
>             Log.info("OUTPUT: " + fileList)
>          }
>        }
>
> }
>
> But I'm not sure from your code wht you do with the output of your
> listFilesInDir since that never gets to be rendered.
>
> I strongly recommend using CometActor whenever you want to render
> something asynchronously. It does a lots of good things for you.
>
> Br's,
> Marius
>
> On Feb 16, 9:33 am, soumik <[email protected]> wrote:
>
> > Hi Marius,
>
> >  Thanks for your response. I'm sorry for mis-communicating my problem
> > earlier. As you pointed out the problem doesn't occur when the call to
> > the function is made from a CometActor.
> > In my case too, it was not a CometActor. Rather, it was the LiftActor.
> > (Sometime back we had different CometActors for different feature
> > threads, now we have 1 single CometActor which takes care of the
> > display and different LiftActor threads which do the feature related
> > stuff. Hence the confusion on my part).
>
> > Anyways, here's the relevant code:
> > -------------------------------------
> > object TheVideoPlayerThread extends LiftActor
> > {
> >    val threadName = "FileManager"
>
> >    def listFilesInDir(dirName:String): NodeSeq =
> >    {
> >       Log.info("Recursing for: " + dirName)
> >       val files = (new java.io.File(dirName)).listFiles
>
> >       def showFile1() = "AAA"
>
> >       <li class="fileElem" id="dir">{dirName}</li>
> >          <ul>
> >          {files.flatMap(f => {
> >               if (f.isDirectory())
> >               {
> >                  Log.info("Directory: " + f.toString)
> >                  listFilesInDir(f.toString)
> >               }
> >               else
> >               {
> >                  Log.info("Regular file: " + f.getName)
> >                  <li class="fileElem" id="regfile">
> >                   {SHtml.link("", () => showFile1,
> > Text(f.getName)) }                   //This is the line causing the
> > issue
> >                  </li>
> >               }
> >            }
> >          )}
> >          </ul>
> >    }
>
> >    protected def messageHandler = {
> >        case FileManagerMsg(someMsg) =>
> >        {
> >            var fileList = listFilesInDir("/Users/soumik/Movies/")
> >            Log.info("OUTPUT: " + fileList)
> >        }
> >   }
> > -------------------------------------
> > (I've omitted some of code in this thread which are not related to the
> > file listing functionality.)
> > The problem I see is as soon as I encounter the first file in the
> > directory specified, it prints - "Regular file: <filename>", but after
> > that I don't see the log - "OUTPUT - ...". The function never returns.
> > Same function works perfectly in a CometActor and I see the nodeseq of
> > files in <li> tags to be rendered.
> > Also in the same method in my LiftActor object, if I replace the line:
> > {SHtml.link("", () => showFile1, Text(f.getName)) }
> > with just
> > {f.getName}
> > I see the function return and print the log "OUTPUT - .." with the
> > list of all the files as <li> entries.
>
> > I'm sorry I couldn't give a more concrete example which you could run
> > and reproduce the issue. I'll appreciate if you could just give this
> > function a try from any LiftActor object and check the output on
> > console.
> >  Also, I'm still on 1.1-SNAPSHOT. I've a fairly big codebase, so not
> > sure if migrating to 2.0-SNAPSHOT will cause any other issues,
> > particularly with jquery(i'm using lot of jquery plugins dependent on
> > 1.3.2, not sure if all of them works nicely with 1.4).
>
> > Thanks,
> > Soumik
>
> > On Feb 15, 11:22 pm, Marius <[email protected]> wrote:
>
> > > I don't think the cause is in SHtml. I tried your code from a snippet
> > > and from a Comet actor and there was no lock whatsoever. But I did use
> > > lift 2.0-SNAPSHOT. can you try with 2.0-SNAPSHOT ?
>
> > > Br's,
> > > Marius
>
> > > On 15 feb., 15:20, soumik <[email protected]> wrote:
>
> > > > Hi,
> > > >  I'm using 1.1-SNAPSHOT lift release and am experiencing strange
> > > > behaviour when trying to output a NodeSeq formed from nested NodeSeq &
> > > > Scala code.
>
> > > > To highlight the problem let me show you the code I'm trying to
> > > > execute:
> > > > -----------------------------------
> > > > def listFilesInDir(dirName:String): NodeSeq =
> > > >    {
> > > >       Log.info("Recursing for: " + dirName)
> > > >       val files = (new java.io.File(dirName)).listFiles
>
> > > >       def playFile1() = "AAA"
>
> > > >       <li class="fileElem" id="dir">{dirName}</li>
> > > >          <ul>
> > > >          {files.flatMap(f => {
> > > >               if (f.isDirectory())
> > > >               {
> > > >                  Log.info("Directory: " + f.toString)
> > > >                  listFilesInDir(f.toString)
> > > >                  <span></span>
> > > >               }
> > > >               else
> > > >               {
> > > >                  Log.info("Regular file: " + f.getName)
> > > >                  <li class="fileElem" id="regfile">
> > > >                   {SHtml.link("", () => playFile1,
> > > > Text("Something")) }                 /* Problem in this line */
> > > >                  </li>
> > > >               }
> > > >            }
> > > >          )}
> > > >          </ul>
> > > > -----------------------------------
> > > > I'm trying to render the output of the above function in a comet
> > > > actor. The problem i see is with the highlighted line of code. When
> > > > the execution reaches this line of code, it gets stuck; the function
> > > > doesn't return and i don't get a NodeSeq to render.
> > > > However, for some reason if I change the highlighted line of code to
> > > > say:
> > > > {f.getName}
> > > > I get the proper NodeSeq which lists all the files in the directory.
>
> > > > Seems to me that the SHtml class functions are encountering an error
> > > > scenario(frm which its unable to recover). I've tried a couple of
> > > > SHtml functions(a, text, link, submit etc.) all of them show the same
> > > > problem, but if I use some other scala code it executes properly.
>
> > > > Could anyone look into this and verify whether this is indeed a bug
> > > > with the SHtml functions?
>
> > > > Thanks,
> > > > Soumik

-- 
You received this message because you are subscribed to the Google Groups 
"Lift" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/liftweb?hl=en.

Reply via email to