How to render ajax response that needs dynamic snippets?

54 views
Skip to first unread message

Jeppe Nejsum Madsen

unread,
Oct 26, 2009, 6:39:25 AM10/26/09
to lif...@googlegroups.com
Hi,

I'm using the same rewriting code as in CRUDify, so that URLs like

tender/results/2

show a result page for the tender with id 2. This page contains lots of
snippets, defined (as in CRUDify) within a SnippetTest partial function.

The page renders fine when hit for the first time. The user can change
various parameters on the page, causing some of the content on the page
to change using ajax.

I can't seem to render the content in this ajax call. It doesn't render
the snippets defined in the snippets partial function, but renders other
(ie global snippets) ok. This is an example of a select element, that
should change some content on the page:

case ("result.name", Full(wp: Result)) => s => Text(wp.name.is)
case ("result.select", Full(result: Result)) => {
curResult(Full(result));
s => {
def doSelect(msg: NodeSeq) =
ajaxSelectObj(lcs.map(lc => (lc, lc.name.is)), Empty,
lc => {
val nodeseq = TemplateFinder.findAnyTemplate(List("result", "results")).open_!
val sub = chooseTemplate("lift", "result.result_comparison", nodeseq)
val markup = S.session.open_!.processSurroundAndInclude("mypage", sub)
println("processed:"+markup)
SetHtml("mylc", Text(lc.name.is))
})


bind("select", s,
"lc1" -> doSelect _,
"lc2" -> doSelect _
)
}
}

Here, markup does not contain the contents of the snippet result.name,
but does contain the results of other, standalone, snippets.

Any clues? Or is there a better way to render partial page content?

/Jeppe

David Pollak

unread,
Oct 26, 2009, 12:45:14 PM10/26/09
to lif...@googlegroups.com
The ajax rendering is not done in the same SiteMap context as the full page request, so the page-specific snippets are not being accessed.  This is an interesting problem and deserves a ticket.  I'll capture the current custom snippet context when ajax requests for a given page are executed.
--
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

Jeppe Nejsum Madsen

unread,
Oct 26, 2009, 12:52:20 PM10/26/09
to lif...@googlegroups.com
David Pollak <feeder.of...@gmail.com> writes:

> The ajax rendering is not done in the same SiteMap context as the full page
> request, so the page-specific snippets are not being accessed. This is an
> interesting problem and deserves a ticket. I'll capture the current custom
> snippet context when ajax requests for a given page are executed.

Do you want me to create a ticket or?

Is there a workaround for this (or perhaps a better way to solve the
problem :-)

I guess I can always extract the body of the snippet into a method and
just invoke this from the ajax call as well as the snippet......

/Jeppe

David Pollak

unread,
Oct 26, 2009, 12:55:10 PM10/26/09
to lif...@googlegroups.com
On Mon, Oct 26, 2009 at 9:52 AM, Jeppe Nejsum Madsen <je...@ingolfs.dk> wrote:

David Pollak <feeder.of...@gmail.com> writes:

> The ajax rendering is not done in the same SiteMap context as the full page
> request, so the page-specific snippets are not being accessed.  This is an
> interesting problem and deserves a ticket.  I'll capture the current custom
> snippet context when ajax requests for a given page are executed.

Do you want me to create a ticket or?

Yes.
 

Is there a workaround for this (or perhaps a better way to solve the
problem :-)

If I understand your issue, the best thing to do is capture the special snippet state in ajax requests.
 

I guess I can always extract the body of the snippet into a method and
just invoke this from the ajax call as well as the snippet......

You won't be the first person to experience this.
 

/Jeppe


Jeppe Nejsum Madsen

unread,
Oct 26, 2009, 4:00:12 PM10/26/09
to lif...@googlegroups.com
David Pollak <feeder.of...@gmail.com> writes:

> On Mon, Oct 26, 2009 at 9:52 AM, Jeppe Nejsum Madsen <je...@ingolfs.dk>wrote:
>
>>
>> David Pollak <feeder.of...@gmail.com> writes:
>>
>> > The ajax rendering is not done in the same SiteMap context as the full
>> page
>> > request, so the page-specific snippets are not being accessed. This is
>> an
>> > interesting problem and deserves a ticket. I'll capture the current
>> custom
>> > snippet context when ajax requests for a given page are executed.
>>
>> Do you want me to create a ticket or?
>>
>
> Yes.

Done. http://github.com/dpp/liftweb/issues/#issue/134


/Jeppe

Reply all
Reply to author
Forward
0 new messages