RequestVar not being set in assignment-callback of an ajax-POST

313 views
Skip to first unread message

Andreas Joseph Krogh

unread,
Nov 24, 2011, 5:10:12 PM11/24/11
to liftweb
Hi.

I'm wondering if this bug has anything to do with: http://www.assembla.com/spaces/liftweb/tickets/980

I'm simply trying to access a request-var from an assignment-callback of SHtml.text() and it's not set. The strange thing is that I once in a while experience that it *is* set, but cannot reproduce it...

Simple code ( https://github.com/andreak/on-example-requestvartest)

Template:
<form class="lift:form.ajax">
    <div class="lift:TestSnippet">
        <input type="text"/>
        <input type="submit"/>
    </div>
</form>


Snippet:

class TestSnippet {

    object fiskVar extends RequestVar[Box[String]](Empty)

    def render = {
        fiskVar.set(Full("fiskVar from render"))
        ":text" #> SHtml.text("", (s) => {
            println("submit assignment-callback: fiskVar: " + fiskVar.get) // Prints Empty
        }, "onblur" -> SHtml.onEvent((s) => {
            println("onblur: fiskVar: " + fiskVar.get)
        })._2.toJsCmd) &
        ":submit" #> SHtml.ajaxSubmit("Drus", () => {})
    }

}

The log-output (STDOUT) is:

onblur: fiskVar: Full(fiskVar from render)
submit assignment-callback: fiskVar: Empty

Why is the second Empty?

I'm using 2.4-M5 with Scala-2.9.1

Thanks for any help.
-- 
Andreas Joseph Krogh <and...@officenet.no> - mob: +47 909 56 963
Senior Software Developer / CTO - OfficeNet AS - http://www.officenet.no
Public key: http://home.officenet.no/~andreak/public_key.asc

Jeppe Nejsum Madsen

unread,
Nov 25, 2011, 3:50:40 AM11/25/11
to lif...@googlegroups.com

My guess is, it's the different life cycles of RequestVars

The onBlur is an ajax request so it uses the same RequestVars as was on
the original page but the submit is a different request and gets new
values.

Oh wait the submit is also ajax...hmm so much for that theory :-)

Could be though, that the submit is still considered
"different"...haven't looked at the code.

/Jeppe

Andreas Joseph Krogh

unread,
Nov 25, 2011, 4:03:12 AM11/25/11
to lif...@googlegroups.com

Exactly:-)

> Could be though, that the submit is still considered
> "different"...haven't looked at the code.

By the way RequestVars are advertised this should work if I'm not mistaken... The strange thing is that this behavior goes way back and is not new (I've tested with 2.3 and different scala-versions).

The strange thing is that I experienced it working once or twice but am not able to reproduce.

Sören Kress

unread,
Nov 25, 2011, 5:05:46 AM11/25/11
to lif...@googlegroups.com

Could be though, that the submit is still considered

"different"...haven't looked at the code.

If you change the last line of the render method from

":submit" #> SHtml.ajaxSubmit("Drus", () => {})

to 

":submit" #> SHtml.ajaxSubmit("Drus", () => {println("submit fun: " + fiskVar.get)})

... you'll get this output:

submit assignment-callback: fiskVar: Empty
submit fun: Full(fiskVar from render)

So it seems as if only the callback from the text input field is mistaken.

Best regards
Soeren

Andreas Joseph Krogh

unread,
Nov 25, 2011, 5:39:49 AM11/25/11
to lif...@googlegroups.com

Yes, I call this the "assignmentCallback" (because it's often in this callback you assign the input to something). For various reasons I need to access a request-var in this callback so it's a blocker for me.

David Pollak

unread,
Nov 28, 2011, 12:06:17 PM11/28/11
to lif...@googlegroups.com
Yes... it's 980.  Each of the Ajax callbacks perform an explicit RequestVar restore to give you the same environment.  The onEvent doesn't do the RenderVar restore.  This will all be fixed when I get to 980.

As a process issue, we're in semi code slush per Indrajit's latest note.  If I tackle 980, it will be a major change to how Lift handles Ajax and should be done with lots of heads up to developers.  What's the thought on another 2.4 milestone versus getting 980 into 2.5?

--
Lift, the simply functional web framework: http://liftweb.net
Code: http://github.com/lift
Discussion: http://groups.google.com/group/liftweb
Stuck? Help us help you: https://www.assembla.com/wiki/show/liftweb/Posting_example_code



--
Visi.Pro, Cloud Computing for the Rest of Us http://visi.pro
Lift, the simply functional web framework http://liftweb.net


AGYNAMIX Torsten Uhlmann

unread,
Nov 28, 2011, 12:23:29 PM11/28/11
to lif...@googlegroups.com
David,

From our point of view (see that other thread that also exposes the 980 issue) we have found a workaround.
So there is currently no hard pressing reason to force a solution into 2.4.

Thanks for your research!
Torsten.

Andreas Joseph Krogh

unread,
Nov 28, 2011, 2:04:46 PM11/28/11
to lif...@googlegroups.com
On 11/28/2011 06:06 PM, David Pollak wrote:
> Yes... it's 980. Each of the Ajax callbacks perform an explicit
> RequestVar restore to give you the same environment. The onEvent
> doesn't do the RenderVar restore. This will all be fixed when I get
> to 980.
>
> As a process issue, we're in semi code slush per Indrajit's latest
> note. If I tackle 980, it will be a major change to how Lift handles
> Ajax and should be done with lots of heads up to developers. What's
> the thought on another 2.4 milestone versus getting 980 into 2.5?

From what I can see there are no more critical issues in 2.4-SNAPSHOT so
getting 2.4 released seems pretty ok by me. Would be better for that
AJAX-overhaul to make it into 2.5 I think. That doesn't mean it's less
important tho...

David Pollak

unread,
Nov 28, 2011, 2:05:56 PM11/28/11
to lif...@googlegroups.com
On Mon, Nov 28, 2011 at 11:04 AM, Andreas Joseph Krogh <and...@officenet.no> wrote:
On 11/28/2011 06:06 PM, David Pollak wrote:
> Yes... it's 980.  Each of the Ajax callbacks perform an explicit
> RequestVar restore to give you the same environment.  The onEvent
> doesn't do the RenderVar restore.  This will all be fixed when I get
> to 980.
>
> As a process issue, we're in semi code slush per Indrajit's latest
> note.  If I tackle 980, it will be a major change to how Lift handles
> Ajax and should be done with lots of heads up to developers.  What's
> the thought on another 2.4 milestone versus getting 980 into 2.5?

From what I can see there are no more critical issues in 2.4-SNAPSHOT so
getting 2.4 released seems pretty ok by me.

It'd be great to have a prioritized list of 2.4 release-blocking issues.  Anyone want to chime in?
 
Would be better for that
AJAX-overhaul to make it into 2.5 I think. That doesn't mean it's less
important tho...

--
Andreas Joseph Krogh <and...@officenet.no> - mob: +47 909 56 963
Senior Software Developer / CTO - OfficeNet AS - http://www.officenet.no
Public key: http://home.officenet.no/~andreak/public_key.asc

--
Lift, the simply functional web framework: http://liftweb.net
Code: http://github.com/lift
Discussion: http://groups.google.com/group/liftweb
Stuck? Help us help you: https://www.assembla.com/wiki/show/liftweb/Posting_example_code

Jeppe Nejsum Madsen

unread,
Nov 29, 2011, 3:16:24 AM11/29/11
to lif...@googlegroups.com
David Pollak <feeder.of...@gmail.com> writes:

> On Mon, Nov 28, 2011 at 11:04 AM, Andreas Joseph Krogh <and...@officenet.no
>> wrote:
>
>> On 11/28/2011 06:06 PM, David Pollak wrote:
>> > Yes... it's 980. Each of the Ajax callbacks perform an explicit
>> > RequestVar restore to give you the same environment. The onEvent
>> > doesn't do the RenderVar restore. This will all be fixed when I get
>> > to 980.
>> >
>> > As a process issue, we're in semi code slush per Indrajit's latest
>> > note. If I tackle 980, it will be a major change to how Lift handles
>> > Ajax and should be done with lots of heads up to developers. What's
>> > the thought on another 2.4 milestone versus getting 980 into 2.5?
>>
>> From what I can see there are no more critical issues in 2.4-SNAPSHOT so
>> getting 2.4 released seems pretty ok by me.
>
>
> It'd be great to have a prioritized list of 2.4 release-blocking issues.
> Anyone want to chime in?

There are no tickets left for the 2.4 milestone (there is no 2.4
milestone :-)

I just browsed the tickets in "No milestone" and nothing there seems to
be a blocker....so unless someone speaks up and points to a blocking
ticket, I guess there are none.

/Jeppe

David Pollak

unread,
Nov 8, 2012, 12:48:23 PM11/8/12
to lif...@googlegroups.com


On Wed, Nov 7, 2012 at 9:34 PM, Austen Holmes <austen...@gmail.com> wrote:
I don't want to resurrect an old thread, but I think this issue just bit me for a few hours this evening.

The basic scenario is almost identical to the original poster, except I'm using:

".selector [onchange]" #> SHtml.onEvent(_ => Set some variable)

I've been able to work around it using snippet class variables (or locally scoped variables with closure), but I was hoping to be able to set some information in a requestVar and have multiple snippets update and reference it via ajax callbacks.  (in which case I can't just use a snippet class variable.)  Is there another pattern in lift for sharing information across snippets?

This was fixed a long time ago. What version of Lift are you using?
 
--
--
Lift, the simply functional web framework: http://liftweb.net
Code: http://github.com/lift
Discussion: http://groups.google.com/group/liftweb
Stuck? Help us help you: https://www.assembla.com/wiki/show/liftweb/Posting_example_code
 
 
 



--
Telegram, Simply Beautiful CMS https://telegr.am

Austen Holmes

unread,
Nov 8, 2012, 2:30:07 PM11/8/12
to lif...@googlegroups.com
I was using 2.5-M2.  

I did some more digging early this morning (or late last night...) and looked at more recent threads.  It looked like I was seeing the same problem described here:

https://groups.google.com/forum/?fromgroups=#!topic/liftweb/ZrSzdAOVRRY

I switched to 2.5-snapshot this morning and everything worked as expected.

Sorry again for bringing back an old thread.

-Austen

Reply all
Reply to author
Forward
0 new messages