Forms with Mapper + reading from HTML table

63 views
Skip to first unread message

Uros Nedic

unread,
Apr 6, 2012, 4:53:35 AM4/6/12
to lif...@googlegroups.com
Hi all,

  This time I have two problems I'm desperately trying to solve in Lift.

  First one is related with doing Forms in Mapper. I saw very interesting tags like
<lift:field_label name="id"/> in Record. Since I'm using Mapper, does anyone
have an idea how I can develop my own Forms and click "Save" button? I need it
because want to be able to organize Form fields on my own way with my Field titles.

Second one is related with pure HTML tables. Let say, I have one HTML table rendered
on the screen. I used JavaScript to enable user to modify that table. After he clicks "Save",
I would like to read cells from the table and process them. I have some ideas in my mind
but all of them look more/less complex. Probably there are some simple solution.

Again thank you in advance,
Uros

David Pollak

unread,
Apr 6, 2012, 12:47:18 PM4/6/12
to lif...@googlegroups.com
please read http://simply.liftweb.net/index-Chapter-4.html#toc-Chapter-4  That covers most of what you need for form with Lift.

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


Uros Nedic

unread,
Apr 6, 2012, 5:33:28 PM4/6/12
to lif...@googlegroups.com
Thank you! Again I missed whole important chapter. I looked at the Mapper stuff and completely
forgot this. By the way, do you have idea about my second question?

Uros

Nice Placer

unread,
Apr 7, 2012, 10:32:38 PM4/7/12
to lif...@googlegroups.com
Hi Uros.

Not sure, if this is, what you are looking for, but I would do something like this:

in your template:

<div class="l:Yoursnippet.submit?form=post">
<div class="lift:Yoursnippet.showtable"></div><br />
<input type="submit" value="Update table"/></div>

and in your snippet you could use SHtml to fill your table:

  def showtable: NodeSeq = {
    var nodeSeq: NodeSeq = NodeSeq.Empty
...
...
    oneTableRow foreach(x => nodeSeq ++= <td> ++ SHtml.text({x.value.get}, update(_,x.id.get),"class" -> "tablecell") ++ </td>);
...
...
    {nodeSeq}
  }

  def update: (String,Long) => Any = { (newValue,l) =>
...
...
      val yourMapperTable = YourMapperTable.find(By(YourMapperTable.id, l))
      yourMapperTable.open_!.value(newValue).saveMe()
...
...
  }

  def submit(in: NodeSeq): NodeSeq = {
        in
  }

When submitted, update method is called. There you can use id to get the correct mapperjobject. You can then set your new value.
Untested of course. maybe it helps a little.

regards.

Uros Nedic

unread,
Apr 9, 2012, 7:54:54 AM4/9/12
to lif...@googlegroups.com
Thanks for whole effort so far! My challenge follows:

  I got a Box object from Database, then do iteration over that Box.
Let say I have something like this:

var Title=""
...
for {g <- item}
{
 g.projectTitle(Title)
 g.save
}

  When I do g.projectTitle=Title, it says reassignment val. How is
that different from the former one?

  My second, and more important question is why this snippet doesn't
want to modify database object what to do to make it work?. However,
when I put something like g.projectTitle("EuropeAid"), it modifies the
Database correctly.

Thanks,
Uros

Antonio Salazar Cardozo

unread,
Apr 9, 2012, 9:49:38 AM4/9/12
to lif...@googlegroups.com
Hi Uros,
Note that db properties of a Mapper object aren't actually regular variables, they're rich objects. When you call g.projectTitle(Title), you're doing the same as g.projectTitle.apply(Title); that is to say, you're invoking the apply method on the projectTitle object and passing it Title. This sets the value correctly. If you instead try to assign it directly, you find that projectTitle is in fact a val. Even if it weren't, the type of projectTitle would not be a String, it would be a container object designed to let you access that String.

Not sure why you're having trouble saving, but an example project (http://www.assembla.com/spaces/liftweb/wiki/Posting_example_code ) might help diagnose the issue.
Thanks,
Antonio

Uros Nedic

unread,
Apr 10, 2012, 8:32:11 AM4/10/12
to lif...@googlegroups.com
 Thank for this very comprehensive answer. After several hours I found an error in my code
and now everything works fine. For me, it was enough when you said that it should work
to start finding bugs.

  I have other questions now, but I'll put them in separate post.

Uros
Reply all
Reply to author
Forward
0 new messages