User:Tjweir
From Lift
Flot graphs and Lift
CRUD Example: from the mailing list.
Toss up the simple CRUD app I have... pick the right one... do it Tuesday.
[1]
On Dec 29 2007 I posted this if the mailing list... it's here so I write an entry with the answers the list provides.
Hey all,
I'm getting stuck on some basics and I thought rather than spend more
time looking through code and playing the trial and error game, I'll
ask for clarification. I'm positive that what I'm doing is *not* best
practice. :) I'll put anything that comes from this on the wiki as
well.
1) SImply spilling the contents of a model object as read only - is
there a better way than binding each of the members, something like a
read-only toForm? I looked at asHtml, but it appears to be for a
single member, not an object.
David Pollak (dpp) responds: Mapper.asHtml dumps the contents of a model object as XHTML.
2) toForm is great for many cases, but if I would like to offer a
<select> that has a list of all the ForeignKeyed members, then I'm not
sure how to build the form, as toForm does not magically create the
<select> for me.
For example, I have a Client Model object and a Project Model object.
One of the fields in Project is a foreign key to Client. toForm will
create an input field for the ClientID foreign key, but I want a
<select>.
David Pollak (dpp) responds: This is intentional because there's no way to know the scope of what to
select for a foreign key. I'll noodle a little on this and make a code
change that allows the "right thing" (tm) to happen for foreign keys.
You can also implement your own toForm on the element that does what you
want it to.
DPP drops some science!
// This is a snip of my Project Model object.
object clientID extends MappedLongForeignKey(this, Client)
{
override def validSelectValues: Can[List[(Long, String)]] = Full (Client.findAll.map(c => (c.id.is, c.name.is)))
}
This provides a Can of all the available Clients when adding or editing Project.
TODO: make a real entry in the HowTo section.
link title

