Hi, I want the content-part of my webapp to load via ajax, so when the user clicks a link the content is loaded without a refresh of the entire page. Additionally I want the ability to load the pages normally via URL for bookmarking and back button support. What would be the best approach for this in Lift? This example here: http://cookbook.liftweb.net/Show+a+template+inside+a+page+dynamically... looks promising, but it doesn't seem right to do this with every page. Is there a better way? I'm sure someone did already something similar.
While we haven't used it much in some time, we created a Layout class that we use instead of lift:surround. It automatically detects incoming AJAX requests and does not run the surround in those cases, instead returning only the markup within the lift:layout tags so your JavaScript can insert it where appropriate. This should be a reasonable implementation for current Lift:
(Our implementation was using some outdated hacks.)
Additionally, because of how form fields on a page have their associated functions kept in memory server side, you need to look for the data-lift-gc attribute that the above snippet drops on content that is inserted in this way and use it to make additional Lift GC calls. The CoffeeScript in the second file does this.
On Monday, November 5, 2012 1:51:37 PM UTC-5, Christian wrote:
> Hi, > I want the content-part of my webapp to load via ajax, so when the user > clicks a link the content is loaded without a refresh of the entire page. > Additionally I want the ability to load the pages normally via URL for > bookmarking and back button support. What would be the best approach for > this in Lift? This example here: > http://cookbook.liftweb.net/Show+a+template+inside+a+page+dynamically... looks > promising, but it doesn't seem right to do this with every page. Is there a > better way? I'm sure someone did already something similar.
> While we haven't used it much in some time, we created a Layout class that > we use instead of lift:surround. It automatically detects incoming AJAX > requests and does not run the surround in those cases, instead returning > only the markup within the lift:layout tags so your JavaScript can insert > it where appropriate. This should be a reasonable implementation for > current Lift:
> (Our implementation was using some outdated hacks.)
> Additionally, because of how form fields on a page have their associated > functions kept in memory server side, you need to look for the data-lift-gc > attribute that the above snippet drops on content that is inserted in this > way and use it to make additional Lift GC calls. The CoffeeScript in the > second file does this.
> Hope that helps! > Thanks, > Antonio
> On Monday, November 5, 2012 1:51:37 PM UTC-5, Christian wrote:
>> Hi, >> I want the content-part of my webapp to load via ajax, so when the user >> clicks a link the content is loaded without a refresh of the entire page. >> Additionally I want the ability to load the pages normally via URL for >> bookmarking and back button support. What would be the best approach for >> this in Lift? This example here: >> http://cookbook.liftweb.net/Show+a+template+inside+a+page+dynamically... looks >> promising, but it doesn't seem right to do this with every page. Is there a >> better way? I'm sure someone did already something similar.
On Tuesday, November 6, 2012 10:16:39 AM UTC-5, Christian wrote:
> Thanks, that is exactly what I am looking for. There are two small errors > in the snippet, maybe a scala version problem, but I fixed them already.
> Am Montag, 5. November 2012 20:44:57 UTC+1 schrieb Antonio Salazar Cardozo:
>> While we haven't used it much in some time, we created a Layout class >> that we use instead of lift:surround. It automatically detects incoming >> AJAX requests and does not run the surround in those cases, instead >> returning only the markup within the lift:layout tags so your JavaScript >> can insert it where appropriate. This should be a reasonable implementation >> for current Lift:
>> (Our implementation was using some outdated hacks.)
>> Additionally, because of how form fields on a page have their associated >> functions kept in memory server side, you need to look for the data-lift-gc >> attribute that the above snippet drops on content that is inserted in this >> way and use it to make additional Lift GC calls. The CoffeeScript in the >> second file does this.
>> Hope that helps! >> Thanks, >> Antonio
>> On Monday, November 5, 2012 1:51:37 PM UTC-5, Christian wrote:
>>> Hi, >>> I want the content-part of my webapp to load via ajax, so when the user >>> clicks a link the content is loaded without a refresh of the entire page. >>> Additionally I want the ability to load the pages normally via URL for >>> bookmarking and back button support. What would be the best approach for >>> this in Lift? This example here: >>> http://cookbook.liftweb.net/Show+a+template+inside+a+page+dynamically... looks >>> promising, but it doesn't seem right to do this with every page. Is there a >>> better way? I'm sure someone did already something similar.
class Layout { def render(xhtml: NodeSeq) = { if (S.request.map(_.ajax_?) == Full(true)) { S.skipXmlHeader = true S.skipDocType = true
/** * We add a data-gc-version attribute to the root element. This * attribute is read client-side to send a __Lift_GC message back to * the server to make sure we don't garbage collect fields associated * with this page. This page is rendered under a different version than * the original page itself, so we have to avoid garbage collecting * this page's version in addition to the base page. */ val rendered = xhtml match { case group: Group => group.find { case e: Elem => true case _ => false }.map { case e: Elem => e % (new UnprefixedAttribute("data-gc-version", S.renderVersion, Null)) } getOrElse group case other => other }
> Probably because I took my local version, which we barely use anymore, and > updated it to more recent Lift idioms without compiling it O:-)
> Any chance you could let me know the changes so I can update the gist? > Thanks, > Antonio
> On Tuesday, November 6, 2012 10:16:39 AM UTC-5, Christian wrote:
>> Thanks, that is exactly what I am looking for. There are two small errors >> in the snippet, maybe a scala version problem, but I fixed them already.
>> Am Montag, 5. November 2012 20:44:57 UTC+1 schrieb Antonio Salazar >> Cardozo:
>>> While we haven't used it much in some time, we created a Layout class >>> that we use instead of lift:surround. It automatically detects incoming >>> AJAX requests and does not run the surround in those cases, instead >>> returning only the markup within the lift:layout tags so your JavaScript >>> can insert it where appropriate. This should be a reasonable implementation >>> for current Lift:
>>> (Our implementation was using some outdated hacks.)
>>> Additionally, because of how form fields on a page have their associated >>> functions kept in memory server side, you need to look for the data-lift-gc >>> attribute that the above snippet drops on content that is inserted in this >>> way and use it to make additional Lift GC calls. The CoffeeScript in the >>> second file does this.
>>> Hope that helps! >>> Thanks, >>> Antonio
>>> On Monday, November 5, 2012 1:51:37 PM UTC-5, Christian wrote:
>>>> Hi, >>>> I want the content-part of my webapp to load via ajax, so when the user >>>> clicks a link the content is loaded without a refresh of the entire page. >>>> Additionally I want the ability to load the pages normally via URL for >>>> bookmarking and back button support. What would be the best approach for >>>> this in Lift? This example here: >>>> http://cookbook.liftweb.net/Show+a+template+inside+a+page+dynamically... looks >>>> promising, but it doesn't seem right to do this with every page. Is there a >>>> better way? I'm sure someone did already something similar.
> Hm. That's odd. Neither of the changes you made are things I would have > expected to be broken. Which version of Scala are you running? > Thanks, > Antonio
I have one other question: Do you have any experience with Ajax - LiftScreen. It just won't work if I load the LiftScreen via ajax. Seems like there is a redirect going on or the events are not fired.
Am Montag, 5. November 2012 19:51:37 UTC+1 schrieb Christian:
> Hi, > I want the content-part of my webapp to load via ajax, so when the user > clicks a link the content is loaded without a refresh of the entire page. > Additionally I want the ability to load the pages normally via URL for > bookmarking and back button support. What would be the best approach for > this in Lift? This example here: > http://cookbook.liftweb.net/Show+a+template+inside+a+page+dynamically... looks > promising, but it doesn't seem right to do this with every page. Is there a > better way? I'm sure someone did already something similar.