On Mar 31, 9:09 pm, Clemens Oertel <clemens.oer...@gmail.com> wrote:
> Marius:
>
> On 31-Mar-09, at 12:31 PM, marius d. wrote:
>
>
>
> > On Mar 31, 5:06 pm, Clemens Oertel <clemens.oer...@gmail.com> wrote:
> >> - Why not provide the same template mechanism used for forms for HTML
> >> output? This way I can reuse the same template for both - given that
> >> my records have at least dozens, if not even hundreds, of fields,
> >> that'd be a great help.
>
> > Well you can load templates from an html file. Please see
> > LiftSession.findAnyTemplate function.
>
> just thought that, since MetaRecord has
>
> def toForm(inst: BaseRecord): NodeSeq
> and
> def toForm(inst: BaseRecord, template: NodeSeq): NodeSeq
>
> it would only be consistent to provide similar means for HTML output.
>
> > Well I can understand the urge but we do NOT recommend processing
> > templates outside of rendering pipeline. You can call
> > LiftSession.processSurroundAndInclude so that lift tags to be
> > processed etc. but again it is not recommended. The main reason is
> > that your functions that you assume to be bounded during this off-
> > cycle template processing, will not actually be bounded cause it i
> > happening in the wrong place.
>
> > The Record's form template is to allow you to shape the form in any
> > way you like (from markup perspective). But this template is supposed
> > to be very very lightweight in terms of lift's tags. It is just an
> > xhtml fragment and not a full blow page/(lift template).
>
> Mmh, maybe there's a misunderstanding. I was only using the template  
> as indicated in the source code, or so I thought.
>
> May I just provide an abbreviated version of the code that I come up  
> with?
>
> ---- Outer Template ----
> <lift:surround with="default" at="content">
>    <h2>Create a New Site</h2>
>
>    <lift:snippet type="SiteOps.add" form="post" eager_eval="true">
>      <table>
>        <tfoot>
>          <tr>
>            <td colspan="3"><site:submit>Submit</site:submit></td>
>          </tr>
>        </tfoot>
>        <lift:embed what="/sites/_site" />
>      </table>
>    </lift:snippet>
> </lift:surround>
> ---- End Outer Template ----
>
> ---- Embedded Template ----
> <tbody>
> <tr>
>      <td><liftf:field_label name="name">Name</liftf:field_label>:</td>
>      <td><liftf:field name="name">A Hospital Site</liftf:field></td>
>      <td><liftf:field_msg name="name" /></td>
> </tr>
> </tbody>
> ---- End Embedded Template ----
>
> ---- SiteOps ----
>    def add(form: NodeSeq): NodeSeq = {
>      val invokedAs = S.invokedAs
>      val site = Site.create
>
>      def newSite(form: NodeSeq): NodeSeq = {
>        def saveMe(): Unit = {
>          site.validate match {
>            case Nil => site.save ; S.notice("Added " + site.name);  
> S.redirectTo("/sites/")
>            case xs => S.error(xs) ; S.mapSnippet(invokedAs, newSite)
>          }
>        }
>
>        bind("site", Site.toForm(site, form), "submit" ->  
> submit("Save", saveMe))
>      }
>
>      newSite(form)
>    }
> ---- End SiteOps ----
>
> The Site.toForm function is pretty much the same as found in  
> MetaRecord. It will eventually call each fields' toForm function  
> (which are the original Lift 1.0 mapper versions, no changes there).
>
> Am I really doing things outside the rendering pipeline (this is not a  
> rhetorical question)?

Nope sorry ... I misunderstood your case. By bad entirely.

It all seems to work, incl. validation.
> Also, the eagerly evaluated template, which will be passed to toForm,  
> contains only field tags, no other lift tags.
>
> Again, imagine a few dozen different entities, each with a ton of  
> fields. I'm sure you'll understand that I'm hesitant to bind each  
> field manually (once for the list page, once for the display page,  
> once for the add page, and again once for the edit page, even though  
> the last 2 can surely be combined into one bind call in the code).
> I obviously have to declare each field in the model, and refer to it  
> in the view. I really wouldn't mind not having to mention it anywhere  
> inbetween.

This is actually a nice thing to do. Sorry that I misunderstood your
intentions :)

>
> Thank you for all your help,
> Clemens
>
> Clemens Oertel
> clem...@oertel.ca
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Lift" group.
To post to this group, send email to liftweb@googlegroups.com
To unsubscribe from this group, send email to 
liftweb+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/liftweb?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to