WiringUI doesn't play nicely with ajaxText (probably a bug)

136 views
Skip to first unread message

David Wasserstrum

unread,
Apr 21, 2011, 1:41:48 PM4/21/11
to lif...@googlegroups.com
I have taken a few passes at debugging this, and from what I can tell if a SHtml.ajaxText() is instantiated within a WiringUI.apply() instantiation, the S.functionMap for the ajax element is lost (or never appended) to the list.

Sample code:

   def ajaxElement = SHtml.ajaxText("this is a test", x => JsCmds.Noop})
   val wiringElement = WiringUI(NodeSeq.Empty, theCell)((number: Long) => (ns: NodeSeq) => {ajaxElement})
   println(S.functionMap.map(_._1))                       

   >> List()

If we placed the above code into a proper snippet page (with a bind()) we do get a ajaxText box which makes callbacks to the server announcing its ID and the newly set value.  The server, however, does not process them as the ajaxText ID was never registered in the S.functionMap.

Interestingly we can change the "def" which I have bolded above to a "val".  This causes the instantiation of the ajaxText box to occur outside of the WiringUI and results in the expected working behavior.

I've spent a bit of time trying to debug.... but the liftweb code is a bit beyond me in this area.

-David

David Pollak

unread,
Apr 21, 2011, 1:53:39 PM4/21/11
to lif...@googlegroups.com
Can you put together an example?

Also, are you using Lift 2.2 or 2.3?  Lots of improvements were made to Wiring from 2.2 to 2.3.

--
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.



--
Lift, the simply functional web framework http://liftweb.net

David Wasserstrum

unread,
Apr 21, 2011, 3:21:39 PM4/21/11
to lif...@googlegroups.com, feeder.of...@gmail.com
Hi David, 
     This repros on Lift 2.3.  How would you like me to submit the example?  I can give you a github repo to clone if you would like.
      Alternatively you could just create these two files and add them into your Boot.scala.
      This code creates two WiringUI elements.  The first (a) has an ajaxText instantiated within the WiringUI initializer.  The second (b) has an ajaxText element that was instantiated before the WiringUI.
      When changes occur to the first (a) no call-back is invoked on the server side.  When changes occur to the second (b) a call-back is invoked.  It appears that the first (a) has not registered its ajaxText function's callback.

--- WiringUITrouble.html ---
  <head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
    <script id="jquery" src="/classpath/jquery.js" type="text/javascript"/>
  </head>
  <body>
    <lift:WiringUITrouble form="POST"/>
  </body>
</html>

----WiringUITrouble.scala----
package code
package snippet

import scala.xml.{NodeSeq, Text}
import net.liftweb.util._
import net.liftweb.common._
import java.util.Date
import code.lib._
import Helpers._
import net.liftweb.http.js.JsCmds
import net.liftweb.http.{WiringUI, S, SHtml}

class WiringUITrouble {
  def render(xhtml: NodeSeq): NodeSeq = {
    val theCell = ValueCell(5L)
    def ajaxElement = SHtml.ajaxText("test box", x => {JsCmds.Alert("post-back worked!")})
    val wiringElementA = WiringUI(NodeSeq.Empty, theCell)((number: Long) => (ns: NodeSeq) => {ajaxElement})

    val ajaxElementB = ajaxElement; //Initalize outside of scope
    val wiringElementB = WiringUI(NodeSeq.Empty, theCell)((number: Long) => (ns: NodeSeq) => {ajaxElementB})

    <div>
      <div>Change the text in the boxes below and then click outside of them (to change focus).</div>
      <div>Box a and b both make ajax call-backs to the server, however only box b executes the handler.</div>
      <div>We can also see that only box B has a registered function in the S.functionMap.</div>
      <div>a: {wiringElementA}</div>
      <div>b: {wiringElementB}</div>
      <div>registered functions: {S.functionMap.map(_._1)}</div>
    </div>
david wasserstrum (dw)
  206.949.5328 (cell)
  davidwasserstrum (skype)

Screen shot 2011-04-21 at 3.19.05 PM.png

David Pollak

unread,
Apr 21, 2011, 3:55:18 PM4/21/11
to David Wasserstrum, lif...@googlegroups.com

http://www.assembla.com/wiki/show/liftweb/Posting_example_code

Thanks

>>> * def* ajaxElement = SHtml.ajaxText("this is a test", x =>

David Wasserstrum

unread,
Apr 21, 2011, 4:43:28 PM4/21/11
to David Pollak, lif...@googlegroups.com
my apologies.

git clone g...@github.com:davewhat/WiringUI-and-ajaxText-trouble.git
  davidwasserstrum (skype)

David Pollak

unread,
Apr 21, 2011, 5:21:31 PM4/21/11
to lif...@googlegroups.com
Dave,

This is a bug. Thanks for finding it and creating a useful case that demonstrates it. Please open a ticket (http://ticket.liftweb.net you must be a watcher of the LiftWeb space on Assembla to open a ticket).

Specifically, the postPageJavaScript list is executed after the function table is loaded into the session, rather than before.

Thanks,

David

David Wasserstrum

unread,
Apr 21, 2011, 6:05:59 PM4/21/11
to lif...@googlegroups.com, David Pollak
David,
   I have left the bug unassigned as you did not specifically request to have it assigned to you.  https://www.assembla.com/spaces/liftweb/tickets/983-ajaxtexts-created-within-a-wiringui-do-not-work
    I am very excited to see WiringUI and have been very happy with my interactions with it thus far.  It is everything that I had described to you in our conversation at foursquare hq a few months back.... I had never dreamed that it would come to fruition so quickly.  Gone are the days of "write twice".

Thank you again,
-David
  davidwasserstrum (skype)

TylerWeir

unread,
Apr 22, 2011, 8:21:26 AM4/22/11
to lif...@googlegroups.com, David Pollak
I vote for David W for the Happy Liftr for providing a _perfect_ example when engaging about a possible bug.

Paul Dale

unread,
Apr 24, 2011, 4:45:58 PM4/24/11
to lif...@googlegroups.com

Seconded ...

On Fri, Apr 22, 2011 at 2:21 PM, TylerWeir <tyler...@gmail.com> wrote:
I vote for David W for the Happy Liftr for providing a _perfect_ example when engaging about a possible bug.

--

David Pollak

unread,
Apr 25, 2011, 12:00:06 AM4/25/11
to lif...@googlegroups.com
Yeah, not only does he come up with the idea for Wiring, but then he finds an awesome bug in the implementation and does the perfect post describing it.  Rock on!

Mads Hartmann Jensen

unread,
May 11, 2011, 3:20:29 AM5/11/11
to lif...@googlegroups.com
Tyler & Paul, in the future please post nominations to the Happy Lift'r thread :) I had missed these nominations
at first but Antonio was nice enough to notify me so David Wasserstrum can get his prize.

Cheers,
Mads

TylerWeir

unread,
May 11, 2011, 11:01:44 AM5/11/11
to lif...@googlegroups.com
Noted.

:)
Reply all
Reply to author
Forward
0 new messages