[Lift] Re: Using Jx classes to output HTML
On Apr 16, 12:58 am, 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? items is the same with your list variable. use JsVar(list) 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 don't get it. The Jx examples are described there ... It show trivial Jx(div...div) and the JavaScript code generated, then it goes with more complex examples. Do you have some concrete examples of how would you want ti to be described. The lift book chapter have been reviewed by multiple people and I don't recall anyone having troubles with Jx. 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) What java version are you using? SHtml.ajaxButton(Text(Press me), ajaxFunc) should work as it should pass the function and not the function evaluation. You can do partial function application: 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. All examples in the LiftBook have been tested. Jx is a very powerful artifact but for some reason people are staying away from it ... maybe it's because it is not very simple to understand. 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{ JxMap(JsVar(it), Jx(lia href={JsVar(it)}/a/li)) } /ul).toJs) Call(func, JsVar (items)) 2. Jx(ul{ JxMap(JsVar(it), Jx(lia href={JsVar(it)}/a/li)) }/ul).toJs asInstanceOf[AnonFunc].applied(JsVar(items)) ... that should just call the anonymous function constructed by Jx Note that I haven't actaully tested the code but is should work unless I'm missing some parentheses etc. Also Jx is discussed in the LiftBook Br's, Marius On Apr 15, 9:25 pm, glenn gl...@exmbly.com wrote: I'm a novice at this, and I've seen discussions of using Jx classes to output HTML on the client, but how exactly is this done? Are there any complete examples of sending JavaScript functions produced by the Jx classes to the client and running them? Suppose, for example, I have a json object: var list = { tabs: [ {class: posts selected}, {class: comments}, {class: category}, {class: famous}, {class: random} ] } and a function defined so: def renderTabs = Jx(li class='{JsVar(it, class)}'/li) I then want to create tabs on the client with Jx(ul class=tabMenu{JxMap(JsVar(it.tabs), renderTabs)}/ul) How, exactly is this to be done? Obviously, this won't work - the JavaScript function isn't generated: def head(xhtml:NodeSeq): NodeSeq = { val renderTabs = Jx(li class='{JsVar(it, class)}'/li) head script type=text/javascript Jx(ul class=tabMenu{JxMap(JsVar(it.tabs), renderTabs)}/ul) /script /head } I see the value in the Jx classes, if only I knew how to use them. Any help would be appreciated Glenn Silverman --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
[Lift] Re: Using Jx classes to output HTML
Again LiftBook examples are working example ... I can double check today though. Could you send me a minimalistic example (and not just snippet) that does not work? Br's, Marius On Apr 16, 1:19 am, 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. 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{ JxMap(JsVar(it), Jx(lia href={JsVar(it)}/a/li)) } /ul).toJs) Call(func, JsVar (items)) 2. Jx(ul{ JxMap(JsVar(it), Jx(lia href={JsVar(it)}/a/li)) }/ul).toJs asInstanceOf[AnonFunc].applied(JsVar(items)) ... that should just call the anonymous function constructed by Jx Note that I haven't actaully tested the code but is should work unless I'm missing some parentheses etc. Also Jx is discussed in the LiftBook Br's, Marius On Apr 15, 9:25 pm, glenn gl...@exmbly.com wrote: I'm a novice at this, and I've seen discussions of using Jx classes to output HTML on the client, but how exactly is this done? Are there any complete examples of sending JavaScript functions produced by the Jx classes to the client and running them? Suppose, for example, I have a json object: var list = { tabs: [ {class: posts selected}, {class: comments}, {class: category}, {class: famous}, {class: random} ] } and a function defined so: def renderTabs = Jx(li class='{JsVar(it, class)}'/li) I then want to create tabs on the client with Jx(ul class=tabMenu{JxMap(JsVar(it.tabs), renderTabs)}/ul) How, exactly is this to be done? Obviously, this won't work - the JavaScript function isn't generated: def head(xhtml:NodeSeq): NodeSeq = { val renderTabs = Jx(li class='{JsVar(it, class)}'/li) head script type=text/javascript Jx(ul class=tabMenu{JxMap(JsVar(it.tabs), renderTabs)}/ul) /script /head } I see the value in the Jx classes, if only I knew how to use them. Any help would be appreciated Glenn Silverman --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
[Lift] Re: Using Jx classes to output HTML
Perhaps the best way to explain it is to inquire as to just what is the minimal snippet code needed to call a javascript function emitted on the client using Jx ( ). Such a function could be used to dynamically create html, such as a series of li's, from a json object. A skeleton snippet to do this might look like so: def emitFunc(xhtml:NodeSeq):NodeSeq = headscript {JsCrVar(func,Jx(...).toJs)} /script/head It's the snippet to call this function, either immediately on page load, as $(document).ready or later, in response to a button click, perhaps, that has me stumped. I'll be the first to admit there is a steep learning curve here that I'm not anywhere near over yet, but I'm getting there, with a little help, thank you. 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{ JxMap(JsVar(it), Jx(lia href={JsVar(it)}/a/li)) } /ul).toJs) Call(func, JsVar (items)) 2. Jx(ul{ JxMap(JsVar(it), Jx(lia href={JsVar(it)}/a/li)) }/ul).toJs asInstanceOf[AnonFunc].applied(JsVar(items)) ... that should just call the anonymous function constructed by Jx Note that I haven't actaully tested the code but is should work unless I'm missing some parentheses etc. Also Jx is discussed in the LiftBook Br's, Marius On Apr 15, 9:25 pm, glenn gl...@exmbly.com wrote: I'm a novice at this, and I've seen discussions of using Jx classes to output HTML on the client, but how exactly is this done? Are there any complete examples of sending JavaScript functions produced by the Jx classes to the client and running them? Suppose, for example, I have a json object: var list = { tabs: [ {class: posts selected}, {class: comments}, {class: category}, {class: famous}, {class: random} ] } and a function defined so: def renderTabs = Jx(li class='{JsVar(it, class)}'/li) I then want to create tabs on the client with Jx(ul class=tabMenu{JxMap(JsVar(it.tabs), renderTabs)}/ul) How, exactly is this to be done? Obviously, this won't work - the JavaScript function isn't generated: def head(xhtml:NodeSeq): NodeSeq = { val renderTabs = Jx(li class='{JsVar(it, class)}'/li) head script type=text/javascript Jx(ul class=tabMenu{JxMap(JsVar(it.tabs), renderTabs)}/ul) /script /head } I see the value in the Jx classes, if only I knew how
[Lift] Re: Using Jx classes to output HTML
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{ JxMap(JsVar(it), Jx(lia href={JsVar(it)}/a/li)) } /ul).toJs) Call(func, JsVar (items)) 2. Jx(ul{ JxMap(JsVar(it), Jx(lia href={JsVar(it)}/a/li)) }/ul).toJs asInstanceOf[AnonFunc].applied(JsVar(items)) ... that should just call the anonymous function constructed by Jx Note that I haven't actaully tested the code but is should work unless I'm missing some parentheses etc. Also Jx is discussed in the LiftBook Br's, Marius On Apr 15, 9:25 pm, glenn gl...@exmbly.com wrote: I'm a novice at this, and I've seen discussions of using Jx classes to output HTML on the client, but how exactly is this done? Are there any complete examples of sending JavaScript functions produced by the Jx classes to the client and running them? Suppose, for example, I have a json object: var list = { tabs: [ {class: posts selected}, {class: comments}, {class: category}, {class: famous}, {class: random} ] } and a function defined so: def renderTabs = Jx(li class='{JsVar(it, class)}'/li) I then want to create tabs on the client with Jx(ul class=tabMenu{JxMap(JsVar(it.tabs), renderTabs)}/ul) How, exactly is this to be done? Obviously, this won't work - the JavaScript function isn't generated: def head(xhtml:NodeSeq): NodeSeq = { val renderTabs = Jx(li class='{JsVar(it, class)}'/li) head script type=text/javascript Jx(ul class=tabMenu{JxMap(JsVar(it.tabs),
[Lift] Re: Using Jx classes to output HTML
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{ JxMap(JsVar(it), Jx(lia href={JsVar(it)}/a/li))
[Lift] Re: Using Jx classes to output HTML
Marius, This is definitely getting closer. One question? I don't understand why you used this function to handle the button clicked event. val matches = names.filter(e = e.indexOf(value) -1 Where does the 'names' list and 'value' param come from? 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)
[Lift] Re: Using Jx classes to output HTML
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,
[Lift] Re: Using Jx classes to output HTML
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
[Lift] Re: Using Jx classes to output HTML
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))
[Lift] Re: Using Jx classes to output HTML
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{ JxMap(JsVar(it), Jx(lia href={JsVar(it)}/a/li)) } /ul).toJs) Call(func, JsVar (items)) 2. Jx(ul{ JxMap(JsVar(it), Jx(lia href={JsVar(it)}/a/li)) }/ul).toJs asInstanceOf[AnonFunc].applied(JsVar(items)) ... that should just call the anonymous function constructed by Jx Note that I haven't actaully tested the code but is should work unless I'm missing some parentheses etc. Also Jx is discussed in the LiftBook Br's, Marius On Apr 15, 9:25 pm, glenn gl...@exmbly.com wrote: I'm a novice at this, and I've seen discussions of using Jx classes to output HTML on the client, but how exactly is this done? Are there any complete examples of sending JavaScript functions produced by the Jx classes to the client and running them? Suppose, for example, I have a json object: var list = { tabs: [ {class: posts selected}, {class: comments}, {class: category}, {class: famous}, {class: random} ] } and a function defined so: def renderTabs = Jx(li class='{JsVar(it, class)}'/li) I then want to create tabs on the client with Jx(ul class=tabMenu{JxMap(JsVar(it.tabs), renderTabs)}/ul) How, exactly is this to be done? Obviously, this won't work - the JavaScript function isn't generated: def head(xhtml:NodeSeq): NodeSeq = { val renderTabs = Jx(li class='{JsVar(it, class)}'/li) head script type=text/javascript Jx(ul class=tabMenu{JxMap(JsVar(it.tabs), renderTabs)}/ul) /script /head } I see the value in the Jx classes, if only I knew how to use them. Any help would be appreciated Glenn Silverman --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
[Lift] Re: Using Jx classes to output HTML
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. 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{ JxMap(JsVar(it), Jx(lia href={JsVar(it)}/a/li)) } /ul).toJs) Call(func, JsVar (items)) 2. Jx(ul{ JxMap(JsVar(it), Jx(lia href={JsVar(it)}/a/li)) }/ul).toJs asInstanceOf[AnonFunc].applied(JsVar(items)) ... that should just call the anonymous function constructed by Jx Note that I haven't actaully tested the code but is should work unless I'm missing some parentheses etc. Also Jx is discussed in the LiftBook Br's, Marius On Apr 15, 9:25 pm, glenn gl...@exmbly.com wrote: I'm a novice at this, and I've seen discussions of using Jx classes to output HTML on the client, but how exactly is this done? Are there any complete examples of sending JavaScript functions produced by the Jx classes to the client and running them? Suppose, for example, I have a json object: var list = { tabs: [ {class: posts selected}, {class: comments}, {class: category}, {class: famous}, {class: random} ] } and a function defined so: def renderTabs = Jx(li class='{JsVar(it, class)}'/li) I then want to create tabs on the client with Jx(ul class=tabMenu{JxMap(JsVar(it.tabs), renderTabs)}/ul) How, exactly is this to be done? Obviously, this won't work - the JavaScript function isn't generated: def head(xhtml:NodeSeq): NodeSeq = { val renderTabs = Jx(li class='{JsVar(it, class)}'/li) head script type=text/javascript Jx(ul class=tabMenu{JxMap(JsVar(it.tabs), renderTabs)}/ul) /script /head } I see the value in the Jx classes, if only I knew how to use them. Any help would be appreciated Glenn Silverman --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---