I'm working on porting my rails app to lift and have been amazed by
lift. The community
is quite small and seems to be quite friendly as well.
First thing I want to mention is I don't regularly dive into the code
of the frameworks I'm using
but it's really easy to read and navigate through the liftweb source.
The code base is managable
and not that big yet so it's a good time to get familiar with it.
Are the toForm() methods in the lift Mapper/MetaMapper intended for
'production use' or just
to get something up quick and dirty.
I really like the idea of
automatically generating the form
but the xhtml returned includes <tr><td><input.......></td></tr>. I
really tend to keep my form
table-less. I was playing with it yesterday, trying to override the
formatFormLine method in
my model to return something like: <label
for="{displayName}">{displayName}</label>
<input>.... etc. The problem is that the formatFormLine is not the
only method that
is enforcing the use of tables, it is also in one of the toForm()
methods in Mapper.scala.
If i start overriding all these methods, it starts being kind of silly
so i decided going back
to using bind() and then using .toForm() on each MappedString/
MappedTextField etc object
which is fine but it would be nice being able to automatically
generate the entire form and then
use style sheets to lay it out nicely. Is it possible to put these
<tr><td>... into some helper
methods that we can then override?
/**If you change the functions, you globally change the formatting functionality (you can do this in Boot).
* Rules and functions shared by all Mappers
*/
object MapperRules {
/**
* This function converts a header name into the appropriate
* XHTML format for displaying across the headers of a
* formatted block. The default is <th> for use
* in XHTML tables. If you change this function, the change
* will be used for all MetaMappers, unless they've been
* explicitly changed.
*/
var displayNameToHeaderElement: String => NodeSeq = in => <th>{in}</th>
/**
* This function converts an element into the appropriate
* XHTML format for displaying across a line
* formatted block. The default is <td> for use
* in XHTML tables. If you change this function, the change
* will be used for all MetaMappers, unless they've been
* explicitly changed.
*/
var displayFieldAsLineElement: NodeSeq => NodeSeq = in => <td>{in}</td>
/**
* This function is the global (for all MetaMappers that have
* not changed their formatFormElement function) that
* converts a name and form for a given field in the
* model to XHTML for presentation in the browser. By
* default, a table row ( <tr> ) is presented, but
* you can change the function to display something else.
*/
var formatFormElement: (NodeSeq, NodeSeq) => NodeSeq =
(name, form) =>
<xml:group><tr>
<td>{name}</td>
<td>{form}</td>
</tr></xml:group>
}
Thanks David, that's perfect. Will give it a go soon. Not often when
you make a suggestion that
gets implemented the same day :).
Cheers David, it works like a charm! You guys definately won't need
any bugtracking system, the bugs get fixed as soon as they get
spotted!