Marius, Now, we're getting somewhere. I think where I was stumped was how to actually call the function with the correct items and populate the div. That's where (ElemById("items_list") ~> JsFunc("appendChild", Call ("func", JsVar("items")
comes into play, and I thank you for that insight. That being said, you probably only tested in Firefox. Try it in IE. It doesn't populate the div in version 7 when I tried it. Glenn Silverman On Apr 16, 12:20 pm, "marius d." <marius.dan...@gmail.com> wrote: > Glenn, > > I just tested the code and it is working correctly. > > Here is my full class source: > > package lifttest.snippet > > import _root_.scala.xml._ > import _root_.net.liftweb.http.js._ > import JE._ > > import _root_. net.liftweb.http.js.jquery.JqJE._ > import _root_.net.liftweb.http.SHtml._ > import _root_.net.liftweb.util.Helpers._ > import JsCmds._ > > class MyList { > val json = JsObj(("tabs", JsArray( > JsObj(("class" -> "posts selected")), > JsObj(("class" -> "comments")), > JsObj(("class" -> "category")), > JsObj(("class" ->"famous")), > JsObj(("class" -> "random")) > > ))) > > def renderButton(xhtml: Group):NodeSeq = { > bind("ex", xhtml, "button" -> ajaxButton("Press me", () => { > > JsCrVar("items", json) & > JsCrVar("func", Jx(<ul class="tabMenu"> > {JxMap(JsVar("it.tabs"), Jx(<li> > {JsVar("it", "class")}</li>)) > } > </ul>).toJs) & > (ElemById("my_list") ~> JsFunc("appendChild", Call("func", > JsVar("items")))) > }) > ) > } > > } > > and the markup: > > <lift:surround with="default" at="content"> > <lift:MyList.renderButton> > <ex:button/> > </lift:MyList.renderButton> > > <div id="my_list" style="width: 300px; height: 100px; overflow: > auto; border: 1px solid black;"></div> > </lift:surround> > > If you actaully press the button an Ajax request is sent to the server > and the JS code is returned and the list is correctly created. There > is one difference: instead if items_list div ID I used > "my_list" :) ... so in this examplethe list isnot populated on-load > but when the button is pressed. Don't expect the items variable to be > there when the page is loaded ... it is propagated part of the Ajax > response among the other JavaScript code. > > Br's, > Marius > > On Apr 16, 9:43 pm, glenn <gl...@exmbly.com> wrote: > > > Marius, > > > Here's what I tried, based on your sample code: > > > class MyList { > > > val json = JsObj(("tabs", JsArray( > > JsObj(("class" -> "posts selected")), > > JsObj(("class" -> "comments")), > > JsObj(("class" -> "category")), > > JsObj(("class" ->"famous")), > > JsObj(("class" -> "random")) > > > ))) > > > def renderButton(xhtml: Group):NodeSeq = { > > bind("ex", xhtml, "button" -> ajaxButton("Press me", () => { > > val matches = json.toList.filter(e => e.indexOf("tabs") > -1) > > > JsCrVar("items", json) & > > JsCrVar("func", Jx(<ul class="tabMenu"> > > {JxMap(JsVar("it.tabs"), Jx(<li> > > {JsVar("it", "class")}</li>)) > > } > > </ul>).toJs) & > > (ElemById("items_list") ~> JsFunc("appendChild", Call("func", > > JsVar("items")))) > > }) > > > ) > > } > > > } > > > And here's the html: > > > <lift:surround with="default" at="content"> > > > <div> > > <div> > > <lift:MyList.renderButton> > > <ex:button/> > > </lift:MyList.renderButton> > > > </div> > > > <div id="items_list"></div> > > > </div> > > > </lift:surround> > > > The button is emitted but the "items" variable is not. In any case, > > the code above does not do anything. > > Have I got it all wrong? > > > Glenn Silverman > > > On Apr 16, 9:26 am, "marius d." <marius.dan...@gmail.com> wrote: > > > > Glenn, > > > > It looks like there was a typo in the book: > > > > bind("ex", xhtml, > > > "button" -> SHtml.ajaxButton(Text(Press me), ajaxFunc _) // missing > > > underscore for partial function application > > > > If you want to use Jx when say pressing a button ... is it Ajax > > > something that you're looking for? .. such as: > > > > 1. Press the button > > > 2. Return the function generated by Jx and call it by providing a JSON > > > structure > > > > Assume you jave a JsObj containing the JSON structure you want. > > > > var json = JsObj(..) containing the structure: > > > > // { > > > // tabs: [ > > > // {class: posts selected}, > > > // {class: comments}, > > > // {class: category}, > > > // {class: famous}, > > > // {class: random} > > > // ] > > > // } > > > > bind("text", html, > > > "show" -> ajaxButton("Press me", () => { > > > val matches = names.filter(e => e.indexOf(value) > -1) > > > > JsCrVar("items", json) & > > > JsCrVar("func", Jx(<ul>{ > > > JxMap(JsVar("it.tabs"), Jx(<li> > > > {JsVar("it", "class")}</li>)) > > > } > > > </ul>).toJs) & > > > (ElemById("items_list") ~> JsFunc("appendChild", Call > > > ("func", JsVar("items")))) > > > }) > > > ) > > > > where items_list is the ID of a div element. > > > > Would that work for you ? > > > > Br's, > > > Marius > > > > On Apr 16, 6:49 pm, TylerWeir <tyler.w...@gmail.com> wrote: > > > > > There is an odd issue with quotes getting stripped from the book > > > > during Lyx -> pdf. > > > > > This looks to be a case of that. > > > > > On Apr 16, 11:32 am, glenn <gl...@exmbly.com> wrote: > > > > > > Marius, > > > > > > You asked about the Java version I'm using and why I couldn't run the > > > > > Liftbook > > > > > example as-is. > > > > > > My development environment is Eclipse with the scala plugin running > > > > > Java 1.6. > > > > > I assume I'm always compiling with the latest scala/lift libraries, as > > > > > I use maven to > > > > > package and run. > > > > > > I get the following compiler error: > > > > > > "overloaded method value ajaxButton with alternatives (String,() => > > > > > net.liftweb.http.js.JsCmd,(String, String)*)scala.xml.Elem <and> > > > > > (scala.xml.NodeSeq,() => net.liftweb.http.js.JsCmd,(String, String)*) > > > > > scala.xml.Elem cannot be applied to > > > > > (scala.xml.Text,net.liftweb.http.js.JsCmd) TabMenu.scala > > > > > sample/src/ > > > > > main/scala/com/exmbly/scala/sample/snippet Unknown Scala Problem" > > > > > > Changing the call to > > > > > > bind("ex", xhtml, > > > > > "button" -> SHtml.ajaxButton(Text(Press me), () => ajaxFunc) > > > > > > does work, however (Press me needs to be quoted. It's not in the > > > > > book). > > > > > > Glenn Silverman > > > > > > On Apr 16, 6:49 am, David Pollak <feeder.of.the.be...@gmail.com> > > > > > wrote: > > > > > > > On Wed, Apr 15, 2009 at 3:19 PM, glenn <gl...@exmbly.com> wrote: > > > > > > > > Actually, the json example code in the Liftbook works, as long > > > > > > > as you change it to read: > > > > > > > > bind("ex", xhtml, > > > > > > > "button" -> SHtml.ajaxButton(Text(Press me), () => ajaxFunc) > > > > > > > > But this example uses a simple function, alert, and emits it using > > > > > > > JsRaw. > > > > > > > > I would like to see a similar example, but using Jx to emit a > > > > > > > javascript function and have it called. > > > > > > > Jx is for generating functions that generate XML on the client > > > > > > side. It's > > > > > > for building rich client-side applications. > > > > > > > In the button example, the code being called is on the server side, > > > > > > so the > > > > > > client-side code is less relevant. > > > > > > > If you could talk about what you're trying to build, it might be > > > > > > easier to > > > > > > discuss things in concrete terms rather than in abstract terms. > > > > > > > Thanks, > > > > > > > David > > > > > > > > Glenn Silverman > > > > > > > > On Apr 15, 2:58 pm, glenn <gl...@exmbly.com> wrote: > > > > > > > > Marius, > > > > > > > > > I appreciate the reply. Not sure if it helps, though. What's > > > > > > > > with > > > > > > > > (JsVar("items") and why did you use that? > > > > > > > > > The Liftbook is very cryptic on the use of Jx classes. It just > > > > > > > > says, > > > > > > > > > " If we send this generated JavaScript function to client and > > > > > > > > calling > > > > > > > > it by pass the list variable > > > > > > > > above It will create the following document fragment:..." > > > > > > > > > Nothing in the book about how to actually do this. > > > > > > > > > I tried the json example in the book (sec 8.4) and all I got > > > > > > > > emitted > > > > > > > > on the client was: > > > > > > > > <button onclick="lift_ajaxHandler('F560600551708Y4K=true', > > > > > > > > null, > > > > > > > > null); return false;">Press me</button> > > > > > > > > > That doesn't do any good. Generated variable names in emitted > > > > > > > > javascript aren't much good for referencing in scala classes. > > > > > > > > > The book is wrong by the way. This won't compile. > > > > > > > > > bind("ex", xhtml, > > > > > > > > "button" -> SHtml.ajaxButton(Text(Press me), ajaxFunc) > > > > > > > > > You need to do something like this: > > > > > > > > > bind("ex", xhtml, > > > > > > > > "button" -> SHtml.ajaxButton(Text(Press me), () => ajaxFunc) > > > > > > > > > Maybe that's why I'm getting 'F560600551708Y4K=true' emitted. > > > > > > > > > I'm beginning to think nobody has actually written code using > > > > > > > > the Jx > > > > > > > > classes > > > > > > > > that works. > > > > > > > > > Glenn Silverman > > > > > > > > > On Apr 15, 12:30 pm, "marius d." <marius.dan...@gmail.com> > > > > > > > > wrote: > > > > > > > > > > How about > > > > > > > > > > 1. Use a decalred variable > > > > > > > > > > JsCrVar("func", Jx(<ul>{ > > > > > > > > > > > ... > > read more » --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Lift" group. To post to this group, send email to liftweb@googlegroups.com To unsubscribe from this group, send email to liftweb+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/liftweb?hl=en -~----------~----~----~----~------~----~------~--~---