A couple of observations...

First, having some XHTML in your Scala code is not a bad thing.  When the
XHTML declares the meaning (not the layout) of the information, it's my
opinion that it's okay.  This means that:
<ul>{list.map(i => <li>{i}</li>}<ul>
Simply defines an unordered list.  It does not declare how to lay out that
list.  The layout should be controlled by CSS.

Second, you can access the same snippet information in your Scala code as
Lift's layout supports.  For example:

<span id="fruitbat"><lift:embed what="/snippets-hidden/userList"/></span>

In your userList file, you might have a something like:

<ul><lift:UserList><li><user:name/></li></lift:UserList></ul>

So, you want to update the fruitbat span via Ajax:

def myAjaxFunc(): JsCmd = {
  // ... do some user list stuff in the RDBMS
  SetHtml("fruitbat",
          TemplateFinder.findAnyTemplate(List("snippets-hidden",
"userList")) openOr NodeSeq.Empty)
}


So, you are now running the same template (which will invoke the same
snippet) in the Ajax call that you were in your main call.


On Wed, Dec 23, 2009 at 3:51 AM, Adam Warski <[email protected]> wrote:

> Hello,
>
> > With SetHtml you just provide the parent element ID and the NodeSeq
> > you want to render as a child of that parent. You're saying you don;t
> > have the NodeSeq Corresponding to the List but I assume you do have
> > the list right? So assume this Ajax function:
> >
> > def myCallback(): JsCmd = {
> > val myList = ...
> >
> > val html: NodeSeq = myList.flatMap(e => <td>{e toString}</td>)
> >
> > SetHtml("all_todos", html)
> >
> > }
> But then I'm embedding view logic into the code - I wouldn't really want to
> do that. Especially once the list becomes anything more fancy then a simple
> table, I think putting the list-displaying into an html file better.
>
> I tried doing something else, expanding your idea.
> I've put the list-displaying html markup into a template (todo_list.html),
> so now I can reuse it to both display the list and pass it to the snippet
> which handles and binds the form:
>
> Now my form looks like this:
>
> <lift:TD.add form="post">
> <addForm:form>
>  <!-- fields and submit button bound here -->
> </addForm:form>
> <addForm:list>
>  <lift:embed what="todo_list" />
> </addForm:list>
> </lift:TD.add>
>
> <!-- some other code -->
>
> <!-- the list that I want to redraw -->
> <lift:embed what="todo_list" />
>
> In TD.add I have then:
> ...
> def drawList() = list(chooseTemplate("addForm", "list", form))
> def reDraw() = SetHtml("all_todos", drawList())
>
> bind("todo", chooseTemplate("addForm", "form", form),
> "priority" -> todo.priority.toForm,
> "desc" -> todo.desc.toForm,
> "submit" -> submit("New", checkAndSave))
> )
> ...
>
> Is this the right way to go? And is it the "lift" way?
>
> Anyway I can't test it yet because I can't get my form to be submitted with
> ajax. Both surrounding the bind with SHtml.ajaxForm(...) and replacing
> submit with ajaxButton causes the form to stop working (the values in the
> model aren't updated).
>
> Adam
>
> > Br's,
> > Marius
> >
> > On Dec 23, 10:32 am, Adam Warski <[email protected]> wrote:
> >> Hello,
> >>
> >> I'm just starting with Lift, and there's one thing I can't figure out. I
> want to modify the ToDo example from the tutorial so that the "Add" button
> makes an ajax call, adds the element to a list and displays the modified
> result.
> >>
> >> The problem is that I don't know how to redraw the list after the button
> has been pressed. More generally: how to redraw a page fragment with ajax? I
> could do that with SetHtml if I had the NodeSeq corresponding to the list,
> but the button is in an "unrelated" page fragment so it doesn't have it.
> What's the Lift way to solve such problems?
> >>
> >> The page roughly is:
> >>
> >> <lift:TD.add form="post">
> >> <!-- fields an submit button bound here -->
> >> </lift:TD.add>
> >>
> >> <!-- some other code -->
> >>
> >> <!-- the list that I want to redraw -->
> >> <lift:TD.list all_id="all_todos">
> >> ...
> >> </lift:TD.list>
> >>
> >> I was looking through the list archive but didn't find anything. Sorry
> if it's a repeated question :)
> >>
> >> --
> >> Adam
> >
> > --
> >
> > You received this message because you are subscribed to the Google Groups
> "Lift" group.
> > To post to this group, send email to [email protected].
> > To unsubscribe from this group, send email to
> [email protected]<liftweb%[email protected]>
> .
> > For more options, visit this group at
> http://groups.google.com/group/liftweb?hl=en.
> >
> >
>
> --
>
> You received this message because you are subscribed to the Google Groups
> "Lift" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected]<liftweb%[email protected]>
> .
> For more options, visit this group at
> http://groups.google.com/group/liftweb?hl=en.
>
>
>


-- 
Lift, the simply functional web framework http://liftweb.net
Beginning Scala http://www.apress.com/book/view/1430219890
Follow me: http://twitter.com/dpp
Surf the harmonics

--

You received this message because you are subscribed to the Google Groups 
"Lift" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/liftweb?hl=en.


Reply via email to