public
Description: The Lift web framework for Scala
Home | Edit | New

Example: Use TableEditor to manage simple lists

Only in Lift 1.1

TableEditor comes with lift 1.1, thus this code wont work with lift 1.0 web app. Consider checking Upgrading 1.0 → 1.1 how to upgrade to 1.1 to get fancy and supereasy table editor working.

Boot

In Boot (besides adding the page below to the menu as usual):


TableEditor.registerTable("Hospital", Hospital, "Edit hospitals")

There are three parameters. The name to register the table as, to reference in the view; the MetaMapper instance; and the title, as used by the <table:title> tags below.

Layout

In a view, for a quick and simple layout (we use a template with eager_eval):



<lift:TableEditor.edit form="post" table="Hospital" eager_eval="true">
  <lift:embed what="/tableeditor/default" />
</lift:TableEditor.edit>

To understand how to customize the layout, we show the contents of the template referenced above.
Note that the table attribute is the first argument to registerTable above.



<lift:TableEditor.edit form="POST" table="Hospital">
 <head>
   <title><table:title /></title>
  </head>
  <h3><table:title /></h3>
  <table>
    <tr>
      <header:fields>
        <td><field:name /></td>
      </header:fields>
      <td><table:insertBtn /></td>
    </tr>
    <tr>
      <td colspan="5">
      <hr />
      </td>
    </tr>
    <table:items>
    <tr>
      <item:fields>
        <td style="vertical-align: top"><field:form /></td>
      </item:fields>
      <td style="vertical-align: top"><item:removeBtn /></td>
    </tr>
    <tr>
      <td colspan="5">
        <hr />
      </td>
    </tr>
  </table:items>
</table>
<table:saveBtn />
</lift:TableEditor.edit>

Last edited by naleksi, Mon Oct 12 08:27:48 -0700 2009
Home | Edit | New
Versions: