I am very curious about how to share AJAX callbacks across different
snippets, how can we do that by RequestVar, is there any example about
it?
Cheers, Tim
My current solution is just to put the whole things in one snippet
which seems like a mess as below (I tailored so many details to make
it readable):
def render (xhtml : NodeSeq) : NodeSeq = {
var a=new Article
val listTemplate = chooseTemplate("article", "list", xhtml );
val editTemplate = chooseTemplate("article", "edit", xhtml );
def bindList(xhl:NodeSeq): NodeSeq = {
getAllArticles().flatMap(article =>
bind("article", xhl,
"article" -> SHtml.a(() => {
a=article
SetHtml("article_edit", bindEdit(editTemplate))
} ,Text(article.title)
)
)
}
def bindEdit(xhl:NodeSeq): NodeSeq = {
ajaxForm(
bind("article", xhl,
"title" -> text(a.title, a.title=_),
"comment" -> textarea(a.comment, a.comment=_),
"submit" -> ajaxSubmit("Save", () => ajaxSave),
)
)
}
def ajaxSave ={
Model.mergeAndFlush(a)
SetHtml("article_list", bindList(listTemplate))
}
// default binding
bind("article", xhtml,
"list" -> bindList _,
"edit" -> bindEdit _
)
}
All I wanna do is to separate the edit and list into different
snippets but make they can repaint each other by AJAX call
On Mar 19, 7:27 pm, Timothy Perrett <timo...@getintheloop.eu> wrote:
> Whats your use case for sharing an AJAX callback function?
>
> Cheers, Tim
>
> On Mar 19, 4:30 am, BigFool <nanfan...@gmail.com> wrote:
>
> > I read from comments of it and it says:
> > "RequestVars maintain their value throughout the duration of the
> > current HTTP
> > request and any callbacks for servicing AJAX calls associated with
> > the rendered page.
> > RequestVar instances have no value at the beginning of request
> > servicing (excluding
> > AJAX callbacks) and their value is discarded at the end of request
> > processing.
> > They are commonly used to share values across many snippets."
>
> > I am very curious about how to share AJAX callbacks across different
> > snippets, how can we do that by RequestVar, is there any example about
> > it?
--
You received this message because you are subscribed to the Google Groups "Lift" group.
To post to this group, send email to lif...@googlegroups.com.
To unsubscribe from this group, send email to liftweb+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/liftweb?hl=en.
On Mar 20, 1:00 am, David Pollak <feeder.of.the.be...@gmail.com>
wrote:
> > liftweb+u...@googlegroups.com<liftweb%2Bunsu...@googlegroups.com>
> > .
> > For more options, visit this group at
> >http://groups.google.com/group/liftweb?hl=en.
>
> --
> Lift, the simply functional web frameworkhttp://liftweb.net
> Beginning Scalahttp://www.apress.com/book/view/1430219890
I just wanna separate the bindEdit and bindList into different
snippits and they can call each other by AJAX and not refresh the
whole page. Can I do that?
I would appreciate it if there is code
example.
To unsubscribe from this group, send email to liftweb+u...@googlegroups.com.
def list (xhtml : NodeSeq) : NodeSeq = {
val editTemplate = ???? // how to get editTemplate
val listTemplate = chooseTemplate("article", "list", xhtml );
def reDrawEdit(a:Article, drawList:()=>JsCmd) = {
SetHtml("article_edit", bindEdit(editTemplate,a, drawList))
}
def reDrawList = {
SetHtml("article_list", bindList(listTemplate))
}
// default binding
bind("article", xhtml,
"list" -> (x:NodeSeq) => bindList(x, reDrawEdit, reDrawList),
)
}
private def bindList(xhl:NodeSeq, reDrawEdit: Article => JsCmd,
drawList: () => JsCmd): NodeSeq = {
getAllArticles().flatMap(article =>
bind("article", xhl,
"article" -> SHtml.a(() => { reDrawEdit(article,
drawList )} ,Text(article.title)
)
)
}
def edit(xhtml : NodeSeq) : NodeSeq = {
...
}
private def bindEdit(xhl:NodeSeq, a:Articel, reDrawList: () => JsCmd):
NodeSeq = {
...
}
I just don't know how to get the editTemplate for the first time. Only
thing I can get now is to hardcode it for list for the first time but
that is definitely awkward.
On Mar 21, 12:18 am, David Pollak <feeder.of.the.be...@gmail.com>
wrote:
> > <liftweb%2Bunsu...@googlegroups.com<liftweb%252Buns...@googlegroups.com>
To unsubscribe from this group, send email to liftweb+u...@googlegroups.com.