Dynamically addFields(...) of LiftScreen by use ScreenVar failed in a loop.

69 views
Skip to first unread message

Sam

unread,
May 9, 2012, 11:34:48 AM5/9/12
to lif...@googlegroups.com

val books: List[Book] = Books.all  //Book is MappedOneToMany Object

books match {

    case Nil => "was an empty list"

    case x :: xs => {

      object book extends ScreenVar(xs)

      addFields(() => book) // error: type mismatch;
//[INFO]  found   book.type (with underlying type object up)
//[INFO]  required: net.liftweb.util.FieldContainer
//[INFO]       addFields(() => book)

    }

  }

Sam

unread,
May 9, 2012, 11:45:05 AM5/9/12
to lif...@googlegroups.com
Sorry, I have wrote wrong code for process the List.

Now the problem is solved:
  books.foreach(book => {
    object bFields extends ScreenVar(book)
    addFields(() => bFields)
  })

Sam

unread,
May 9, 2012, 12:17:50 PM5/9/12
to lif...@googlegroups.com
Encountered another problem:

  books.foreach(book => {
    object bFields extends ScreenVar(book)
    addFields(() => bFields)
  })

bFields is always the first book's fields of the books list.

For example, three books in books List, names are: A,B,C. But the bFields.name always is "A", therefore addFields had added three "A" in form.

I don't know how to do next...

Thanks for any help.

David Pollak

unread,
May 9, 2012, 12:26:22 PM5/9/12
to lif...@googlegroups.com
addFields is not meant to be used on each Wizard/Screen load.  It's called with a function that dynamically computes the fields.

So, if you want to list N books, you have to write a function that returns the FieldContainer that contains the fields for all the books you want to display.

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


Vladislav Dorokhin

unread,
Oct 5, 2012, 3:50:36 AM10/5/12
to lif...@googlegroups.com

On Wednesday, May 9, 2012 6:17:50 PM UTC+2, Sam wrote:
Encountered another problem:

  books.foreach(book => {
    object bFields extends ScreenVar(book)
    addFields(() => bFields)
  })


  books map ( x => addFields( () => x.title )) 
Reply all
Reply to author
Forward
0 new messages