Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Load content via Ajax (URL based)
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  8 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Christian  
View profile  
 More options Nov 5 2012, 1:51 pm
From: Christian <vette.christ...@gmail.com>
Date: Mon, 5 Nov 2012 10:51:37 -0800 (PST)
Local: Mon, Nov 5 2012 1:51 pm
Subject: Load content via Ajax (URL based)

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.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Antonio Salazar Cardozo  
View profile  
 More options Nov 5 2012, 2:44 pm
From: Antonio Salazar Cardozo <savedfastc...@gmail.com>
Date: Mon, 5 Nov 2012 11:44:57 -0800 (PST)
Local: Mon, Nov 5 2012 2:44 pm
Subject: Re: Load content via Ajax (URL based)

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:

https://gist.github.com/4019866

(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


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Christian  
View profile  
 More options Nov 6 2012, 10:16 am
From: Christian <vette.christ...@gmail.com>
Date: Tue, 6 Nov 2012 07:16:39 -0800 (PST)
Local: Tues, Nov 6 2012 10:16 am
Subject: Re: Load content via Ajax (URL based)

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:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Antonio Salazar Cardozo  
View profile  
 More options Nov 7 2012, 3:23 pm
From: Antonio Salazar Cardozo <savedfastc...@gmail.com>
Date: Wed, 7 Nov 2012 12:23:55 -0800 (PST)
Local: Wed, Nov 7 2012 3:23 pm
Subject: Re: Load content via Ajax (URL based)

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


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Christian  
View profile  
 More options Nov 13 2012, 6:31 pm
From: Christian <vette.christ...@gmail.com>
Date: Tue, 13 Nov 2012 15:31:26 -0800 (PST)
Local: Tues, Nov 13 2012 6:31 pm
Subject: Re: Load content via Ajax (URL based)

Sorry for late response. I forgot about this.

This is the modified version:

package code.snippet

import net.liftweb.http.S
import scala.xml.Group
import scala.xml.NodeSeq
import net.liftweb.common.Full
import scala.xml.Elem
import scala.xml.UnprefixedAttribute
import scala.xml.Null

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
      }

      S.session.map { liftSession =>
        liftSession.processSurroundAndInclude("xhr page", rendered)
      } openOr rendered
    } else {

      val layoutFile =
        S.attr("is").map {
          file => if (file.startsWith("/")) file.substring(1) else
("layouts-hidden/" + file)} openOr "default"
      val insertionPoint = S.attr("at") openOr "content"

      <lift:surround with={ layoutFile } at={ insertionPoint }>{ xhtml

}</lift:surround>

    }
  }

}

Am Mittwoch, 7. November 2012 21:23:56 UTC+1 schrieb Antonio Salazar
Cardozo:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Antonio Salazar Cardozo  
View profile  
 More options Nov 13 2012, 11:52 pm
From: Antonio Salazar Cardozo <savedfastc...@gmail.com>
Date: Tue, 13 Nov 2012 20:52:11 -0800 (PST)
Local: Tues, Nov 13 2012 11:52 pm
Subject: Re: Load content via Ajax (URL based)

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


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Christian  
View profile  
 More options Nov 14 2012, 5:59 am
From: Christian <vette.christ...@gmail.com>
Date: Wed, 14 Nov 2012 02:59:20 -0800 (PST)
Local: Wed, Nov 14 2012 5:59 am
Subject: Re: Load content via Ajax (URL based)

2.9.2

Am Mittwoch, 14. November 2012 05:52:11 UTC+1 schrieb Antonio Salazar
Cardozo:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Christian  
View profile  
 More options Nov 14 2012, 7:11 am
From: Christian <vette.christ...@gmail.com>
Date: Wed, 14 Nov 2012 04:11:38 -0800 (PST)
Local: Wed, Nov 14 2012 7:11 am
Subject: Re: Load content via Ajax (URL based)

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:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »