On Wed, Dec 9, 2009 at 5:35 PM, Xuefeng Wu <ben...@gmail.com> wrote: > doCompetenceB render a button which user click and will pop a dialog for > create a competence. > *The competence have category property, I want this pop dialog know the > category which user already selected from the category tree.* >
That doesn't explain how it's called. English is a weak way to describe things. The best way is a small, runnable example (mvn jetty:run) created as a public GitHub project. I can fork it and make it work the right way for you. > * > * > > On Thu, Dec 10, 2009 at 7:19 AM, David Pollak < > feeder.of.the.be...@gmail.com> wrote: > >> >> >> On Mon, Dec 7, 2009 at 9:14 PM, Xuefeng Wu <ben...@gmail.com> wrote: >> >>> Hi David & Ross, >>> >>> Thank you for your help, >>> I understand RequestVar now, which muse be used in the same request. >>> >>> My case is that I have a tree and a separate button. >>> When use click the tree node, the separate button should know which node >>> is selected. >>> >> >> Without understanding how def *doCompetenceB*(xhtml: NodeSeq,msg: >> String,competence: Competence): NodeSeq = { is called as part of the Ajax >> callback, I can't give you any advice. Sorry. >> >> >>> >>> Right now I replace the separate button when use click the tree node and >>> it worked. >>> I don't want to use session and I think it's better not replace the >>> button. >>> But I don't have idea how to do. >>> >>> On Tue, Dec 8, 2009 at 12:49 PM, David Pollak < >>> feeder.of.the.be...@gmail.com> wrote: >>> >>>> >>>> >>>> On Mon, Dec 7, 2009 at 8:46 PM, Xuefeng Wu <ben...@gmail.com> wrote: >>>> >>>>> My current solution is that when user select a tree node, I replace the >>>>> add button dependence on the node. >>>> >>>> >>>> If you can create a very simple example of what you're trying to do, we >>>> can help you debug the actual, runnable code. >>>> >>>> >>>>> >>>>> >>>>> 2009/12/8 Xuefeng Wu <ben...@gmail.com> >>>>> >>>>> Hi Ross, >>>>>> >>>>>> Yes it's not in the same request. >>>>>> >>>>>> My case is: >>>>>> When user select a tree node, I want to store this nodeId and If user >>>>>> click a button to create a child node, I want to get the selected node. >>>>>> >>>>>> I use ModalDialog when user click the button to create now node. >>>>>> >>>>>> On Tue, Dec 8, 2009 at 11:50 AM, Ross Mellgren <dri...@gmail.com>wrote: >>>>>> >>>>>>> I'm sorry, I'm having trouble following your code, I think too much >>>>>>> of the surrounding code and templates is missing for me to reason about >>>>>>> why >>>>>>> you would have a problem. >>>>>>> >>>>>>> I set up a quick example app, so maybe the code from that will help >>>>>>> you. It is here: >>>>>>> >>>>>>> http://github.com/Dridus/test-rqvarlog >>>>>>> >>>>>>> If I understand you correctly, you're getting a log message like this >>>>>>> one: >>>>>>> WARN - RequestVar test.snippet.HelloWorld$myVar$_ was set but not >>>>>>> read >>>>>>> >>>>>>> This message is from the code I posted: >>>>>>> >>>>>>> package test.snippet >>>>>>> >>>>>>> import _root_.scala.xml.NodeSeq >>>>>>> import _root_.net.liftweb.http.RequestVar >>>>>>> import _root_.net.liftweb.util.Helpers >>>>>>> import Helpers._ >>>>>>> >>>>>>> class HelloWorld { >>>>>>> object myVar extends RequestVar[Int](0) >>>>>>> >>>>>>> def howdy(in: NodeSeq): NodeSeq = Helpers.bind("b", in, "time" -> >>>>>>> (new _root_.java.util.Date).toString) >>>>>>> >>>>>>> def increment(in: NodeSeq): NodeSeq = { >>>>>>> myVar.set(myVar.is + 1) >>>>>>> <div>increment called</div> >>>>>>> } >>>>>>> >>>>>>> def show(in: NodeSeq): NodeSeq = <div>show called -- myVar.is { >>>>>>> myVar.is }</div> >>>>>>> } >>>>>>> >>>>>>> >>>>>>> <lift:surround with="default" at="content"> >>>>>>> <h2>Welcome to your project!</h2> >>>>>>> <p> >>>>>>> <lift:helloWorld.howdy> >>>>>>> <span>Welcome to test-rqvarlog at <b:time/></span> >>>>>>> </lift:helloWorld.howdy> >>>>>>> >>>>>>> <lift:HelloWorld.increment /> >>>>>>> <lift:HelloWorld.increment /> >>>>>>> <!-- <lift:HelloWorld.show /> --> >>>>>>> </p> >>>>>>> </lift:surround> >>>>>>> >>>>>>> If I uncomment the line with HelloWorld.show in the template, the log >>>>>>> message goes away because myVar.is is called. >>>>>>> >>>>>>> If you are still getting the message, then that should mean that you >>>>>>> are not calling myVar.is in the same request. >>>>>>> >>>>>>> HTH, >>>>>>> -Ross >>>>>>> >>>>>>> On Dec 7, 2009, at 10:28 PM, Xuefeng Wu wrote: >>>>>>> >>>>>>> My code : >>>>>>> >>>>>>> >>>>>>> object CompetenceMgr { >>>>>>> >>>>>>> Menu(Loc("Competence", List("competence", "index"), >>>>>>> S.?("Competence"), ifIsLoggedIn, >>>>>>> ... >>>>>>> Loc.Snippet("buildCompetenceDicRows", buildCompetenceDicRows), >>>>>>> Loc.Snippet("addCompetenceB", addCompetenceB), >>>>>>> .... >>>>>>> >>>>>>> private object *_categoryId *extends RequestVar[Long](0) >>>>>>> >>>>>>> //build a competenceDic table >>>>>>> def buildCompetenceDicRows(xhtml: NodeSeq): NodeSeq = { >>>>>>> ... ... >>>>>>> def *makeCategoryRow*(r: Category) = { >>>>>>> ..... >>>>>>> def *categoryNode*: NodeSeq = { >>>>>>> def categoryNodeLinkId = "categoryNodeLinkId-" + r.id >>>>>>> def selectCategoryNode: JsCmd = { >>>>>>> * //here: set the _categoryId, but didn't work* >>>>>>> _categoryId.set(r.id.is) >>>>>>> ... .. >>>>>>> } >>>>>>> <span id={categoryNodeLinkId} class='node_span'>{a(() => >>>>>>> selectCategoryNode, Text(r.title.is))}</span> >>>>>>> } >>>>>>> <tr ><td><span class="folder draggable droppable" >>>>>>> id={categoeryId}>{categoryNode}</span></td></tr> % ("id" -> nodeId) % >>>>>>> ("class" -> nodeClass) >>>>>>> } >>>>>>> def *buildCategoryRows*: NodeSeq = { >>>>>>> val resourceData = Category.categoriesTreeList >>>>>>> (empty /: resourceData)((l, r) => l ++ *makeCategoryRow*(r)) >>>>>>> } >>>>>>> *buildCategoryRows* >>>>>>> } >>>>>>> >>>>>>> //it's a button for create competence >>>>>>> def *addCompetenceB*(xhtml: NodeSeq): NodeSeq = >>>>>>> doCompetenceB(xhtml,"add Competence",null) >>>>>>> //a button for create or edit competence >>>>>>> def *doCompetenceB*(xhtml: NodeSeq,msg: String,competence: >>>>>>> Competence): NodeSeq = { >>>>>>> a(() => { >>>>>>> *//here I try to get the categoryId if it selected.* >>>>>>> val catId: Long = _categoryId.is >>>>>>> S.runTemplate(List("competence","_competence")). >>>>>>> map(ns => >>>>>>> ModalDialog(doCompetenceEditor(ns,catId,competence))) openOr >>>>>>> Alert("Couldn't find _competence template")}, >>>>>>> Text(msg),"class" -> "button" >>>>>>> ) >>>>>>> } >>>>>>> >>>>>>> >>>>>>> >>>>>>> >>>>>>> On Tue, Dec 8, 2009 at 11:02 AM, Ross Mellgren <dri...@gmail.com>wrote: >>>>>>> >>>>>>>> Well if you logically expected it to be read but it wasn't, it might >>>>>>>> indicate a bug to you or help in diagnosis. >>>>>>>> >>>>>>>> I'm not sure I understand your reply fully -- when you added >>>>>>>> myId.is did the log message go away? If not, could you post your >>>>>>>> code? >>>>>>>> >>>>>>>> -Ross >>>>>>>> >>>>>>>> On Dec 7, 2009, at 9:39 PM, Xuefeng Wu wrote: >>>>>>>> >>>>>>>> I use myId.is but get nothing. >>>>>>>> I don't know what I could do with the information. >>>>>>>> >>>>>>>> On Tue, Dec 8, 2009 at 10:19 AM, Ross Mellgren <dri...@gmail.com>wrote: >>>>>>>> >>>>>>>>> I think that message is just informative, letting you know that you >>>>>>>>> don't seem to be using the request var fully (perhaps due to typo, or >>>>>>>>> code >>>>>>>>> refactoring that made it unused, or something.) >>>>>>>>> >>>>>>>>> I think it'll go away if you access the variable somewhere using >>>>>>>>> myId.is. >>>>>>>>> >>>>>>>>> -Ross >>>>>>>>> >>>>>>>>> On Dec 7, 2009, at 9:02 PM, Xuefeng Wu wrote: >>>>>>>>> >>>>>>>>> Hi , >>>>>>>>> >>>>>>>>> When I use RequestVar get the message: RequestVar ....... was set >>>>>>>>> but not read >>>>>>>>> >>>>>>>>> My code like this: >>>>>>>>> object MyMgr { >>>>>>>>> ... >>>>>>>>> Loc.Snippet("myFoo",myFoo) >>>>>>>>> ... >>>>>>>>> object myId extends RequestVar[Long](0) >>>>>>>>> >>>>>>>>> def myFoo(xhtml: NodeSeq): NodeSeq = { >>>>>>>>> .... >>>>>>>>> def selectNode = { >>>>>>>>> >>>>>>>>> myId .set(vId) >>>>>>>>> >>>>>>>>> } >>>>>>>>> .... >>>>>>>>> bind("",xhtml, >>>>>>>>> "node"->a(() => selectNode, Text(nodeName)) >>>>>>>>> ) >>>>>>>>> } >>>>>>>>> >>>>>>>>> } >>>>>>>>> >>>>>>>>> the RequestVar must be used at Class? >>>>>>>>> >>>>>>>>> On Sat, Nov 21, 2009 at 12:09 AM, Ross Mellgren >>>>>>>>> <dri...@gmail.com>wrote: >>>>>>>>> >>>>>>>>>> RequestVar is the standard way of doing this. For example >>>>>>>>>> >>>>>>>>>> object MySharedInformation { >>>>>>>>>> object myData extends RequestVar[List[Thing]](loadThings) >>>>>>>>>> // ^^^^^^^^^^^ ^^^^^^^^^^ >>>>>>>>>> // Type of thing to store How to >>>>>>>>>> initialize >>>>>>>>>> variable first time it's accessed >>>>>>>>>> >>>>>>>>>> private def loadThings: List[Thing] = ... >>>>>>>>>> } >>>>>>>>>> >>>>>>>>>> class Snippet1 { >>>>>>>>>> import MySharedInformation.myData >>>>>>>>>> def render(ns: NodeSeq): NodeSeq = { >>>>>>>>>> myData.is.map(thing => { ... }) >>>>>>>>>> } >>>>>>>>>> } >>>>>>>>>> >>>>>>>>>> class Snippet2 { >>>>>>>>>> import MySharedInformation.myData >>>>>>>>>> ... >>>>>>>>>> } >>>>>>>>>> >>>>>>>>>> The lifetime of the value is during the current request processing >>>>>>>>>> and >>>>>>>>>> any AJAX calls related to it. >>>>>>>>>> >>>>>>>>>> If you really want to initialize it in a snippet, then use a Box >>>>>>>>>> with >>>>>>>>>> a RequestVar, like this: >>>>>>>>>> >>>>>>>>>> object MySharedInformation { >>>>>>>>>> object myData extends RequestVar[Box[List[Thing]]](Empty) >>>>>>>>>> } >>>>>>>>>> >>>>>>>>>> class LoaderSnippet { >>>>>>>>>> import MySharedInformation.myData >>>>>>>>>> def render(ns: NodeSeq): NodeSeq = { >>>>>>>>>> myData.set(Full(...)) >>>>>>>>>> } >>>>>>>>>> } >>>>>>>>>> >>>>>>>>>> class ReaderSnippet { >>>>>>>>>> import MySharedInformation.myData >>>>>>>>>> def render(ns: NodeSeq): NodeSeq = { >>>>>>>>>> // If the data has not been loaded, default to an empty >>>>>>>>>> list >>>>>>>>>> val data = myData.is.openOr(Nil) >>>>>>>>>> ... >>>>>>>>>> } >>>>>>>>>> } >>>>>>>>>> >>>>>>>>>> class OtherReaderSnippet { >>>>>>>>>> import MySharedInformation.myData >>>>>>>>>> def render(ns: NodeSeq): NodeSeq = { >>>>>>>>>> // Do two entirely different things if the data has versus >>>>>>>>>> has not been loaded >>>>>>>>>> myData.is match { >>>>>>>>>> case Full(data) => // do something when the data has >>>>>>>>>> been >>>>>>>>>> loaded >>>>>>>>>> case _ => // do something when the data has not been >>>>>>>>>> loaded >>>>>>>>>> } >>>>>>>>>> } >>>>>>>>>> } >>>>>>>>>> >>>>>>>>>> HTH, >>>>>>>>>> -Ross >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> On Nov 20, 2009, at 10:59 AM, Alex Black wrote: >>>>>>>>>> >>>>>>>>>> > I've got a template page, say foobar.html, that makes a number >>>>>>>>>> of >>>>>>>>>> > calls to functions in a snippet, e.g. mysnippet.foo1, >>>>>>>>>> mysnippet.foo2, >>>>>>>>>> > mysnippet.foo3. >>>>>>>>>> > >>>>>>>>>> > I'd like to do some initial work in foo1, e.g. retrieve some >>>>>>>>>> data and >>>>>>>>>> > do some work on it, then in foo2 and foo3 display parts of that >>>>>>>>>> data. >>>>>>>>>> > >>>>>>>>>> > Whats the easiest way to do this? I think I misunderstood the >>>>>>>>>> lift >>>>>>>>>> > book: >>>>>>>>>> > >>>>>>>>>> > "That means that for each request, Lift creates a new instance >>>>>>>>>> of the >>>>>>>>>> > snippet class to execute. Any changes you make to instance >>>>>>>>>> variables >>>>>>>>>> > will be discarded after the request is processed." >>>>>>>>>> > >>>>>>>>>> > I thought this meant that for a given HTTP request, there would >>>>>>>>>> be one >>>>>>>>>> > (and only one) instance of my snippet, so I could call several >>>>>>>>>> of its >>>>>>>>>> > methods and they could all access the snippet's member >>>>>>>>>> variables, >>>>>>>>>> > which would then be discarded at the end of the request. >>>>>>>>>> > >>>>>>>>>> > Am I going about this wrong? should I only have one snippet >>>>>>>>>> function >>>>>>>>>> > per template? >>>>>>>>>> > >>>>>>>>>> > Thx >>>>>>>>>> > >>>>>>>>>> > - Alex >>>>>>>>>> > >>>>>>>>>> > -- >>>>>>>>>> > >>>>>>>>>> > You received this message because you are subscribed to the >>>>>>>>>> Google >>>>>>>>>> > Groups "Lift" group. >>>>>>>>>> > To post to this group, send email to lift...@googlegroups.com. >>>>>>>>>> > To unsubscribe from this group, send email to >>>>>>>>>> liftweb+unsubscr...@googlegroups.com<liftweb%2bunsubscr...@googlegroups.com> >>>>>>>>>> > . >>>>>>>>>> > For more options, visit this group at >>>>>>>>>> http://groups.google.com/group/liftweb?hl= >>>>>>>>>> > . >>>>>>>>>> > >>>>>>>>>> > >>>>>>>>>> >>>>>>>>>> -- >>>>>>>>>> >>>>>>>>>> You received this message because you are subscribed to the Google >>>>>>>>>> Groups "Lift" group. >>>>>>>>>> To post to this group, send email to lift...@googlegroups.com. >>>>>>>>>> To unsubscribe from this group, send email to >>>>>>>>>> liftweb+unsubscr...@googlegroups.com<liftweb%2bunsubscr...@googlegroups.com> >>>>>>>>>> . >>>>>>>>>> For more options, visit this group at >>>>>>>>>> http://groups.google.com/group/liftweb?hl=. >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> -- >>>>>>>>> Scala中文社区: http://groups.google.com/group/scalacn >>>>>>>>> >>>>>>>>> -- >>>>>>>>> You received this message because you are subscribed to the Google >>>>>>>>> Groups "Lift" group. >>>>>>>>> To post to this group, send email to lift...@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. >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> -- >>>>>>>>> You received this message because you are subscribed to the Google >>>>>>>>> Groups "Lift" group. >>>>>>>>> To post to this group, send email to lift...@googlegroups.com. >>>>>>>>> To unsubscribe from this group, send email to >>>>>>>>> liftweb+unsubscr...@googlegroups.com<liftweb%2bunsubscr...@googlegroups.com> >>>>>>>>> . >>>>>>>>> For more options, visit this group at >>>>>>>>> http://groups.google.com/group/liftweb?hl=en. >>>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> -- >>>>>>>> Scala中文社区: http://groups.google.com/group/scalacn >>>>>>>> >>>>>>>> -- >>>>>>>> You received this message because you are subscribed to the Google >>>>>>>> Groups "Lift" group. >>>>>>>> To post to this group, send email to lift...@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. >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> -- >>>>>>>> You received this message because you are subscribed to the Google >>>>>>>> Groups "Lift" group. >>>>>>>> To post to this group, send email to lift...@googlegroups.com. >>>>>>>> To unsubscribe from this group, send email to >>>>>>>> liftweb+unsubscr...@googlegroups.com<liftweb%2bunsubscr...@googlegroups.com> >>>>>>>> . >>>>>>>> For more options, visit this group at >>>>>>>> http://groups.google.com/group/liftweb?hl=en. >>>>>>>> >>>>>>> >>>>>>> >>>>>>> >>>>>>> -- >>>>>>> Scala中文社区: http://groups.google.com/group/scalacn >>>>>>> >>>>>>> -- >>>>>>> You received this message because you are subscribed to the Google >>>>>>> Groups "Lift" group. >>>>>>> To post to this group, send email to lift...@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. >>>>>>> >>>>>>> >>>>>>> -- >>>>>>> You received this message because you are subscribed to the Google >>>>>>> Groups "Lift" group. >>>>>>> To post to this group, send email to lift...@googlegroups.com. >>>>>>> To unsubscribe from this group, send email to >>>>>>> liftweb+unsubscr...@googlegroups.com<liftweb%2bunsubscr...@googlegroups.com> >>>>>>> . >>>>>>> For more options, visit this group at >>>>>>> http://groups.google.com/group/liftweb?hl=en. >>>>>>> >>>>>> >>>>>> >>>>>> >>>>>> -- >>>>>> Scala中文社区: http://groups.google.com/group/scalacn >>>>>> >>>>> >>>>> >>>>> >>>>> -- >>>>> Scala中文社区: http://groups.google.com/group/scalacn >>>>> >>>>> -- >>>>> You received this message because you are subscribed to the Google >>>>> Groups "Lift" group. >>>>> To post to this group, send email to lift...@googlegroups.com. >>>>> To unsubscribe from this group, send email to >>>>> liftweb+unsubscr...@googlegroups.com<liftweb%2bunsubscr...@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 >>>> Beginning Scala http://www.apress.com/book/view/1430219890 >>>> Follow me: http://twitter.com/dpp >>>> Surf the harmonics >>>> >>>> -- >>>> You received this message because you are subscribed to the Google >>>> Groups "Lift" group. >>>> >>>> To post to this group, send email to lift...@googlegroups.com. >>>> To unsubscribe from this group, send email to >>>> liftweb+unsubscr...@googlegroups.com<liftweb%2bunsubscr...@googlegroups.com> >>>> . >>>> For more options, visit this group at >>>> http://groups.google.com/group/liftweb?hl=en. >>>> >>> >>> >>> >>> -- >>> Scala中文社区: http://groups.google.com/group/scalacn >>> >>> -- >>> You received this message because you are subscribed to the Google Groups >>> "Lift" group. >>> To post to this group, send email to lift...@googlegroups.com. >>> To unsubscribe from this group, send email to >>> liftweb+unsubscr...@googlegroups.com<liftweb%2bunsubscr...@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 >> Beginning Scala http://www.apress.com/book/view/1430219890 >> Follow me: http://twitter.com/dpp >> Surf the harmonics >> >> -- >> You received this message because you are subscribed to the Google Groups >> "Lift" group. >> To post to this group, send email to lift...@googlegroups.com. >> To unsubscribe from this group, send email to >> liftweb+unsubscr...@googlegroups.com<liftweb%2bunsubscr...@googlegroups.com> >> . >> For more options, visit this group at >> http://groups.google.com/group/liftweb?hl=en. >> > > > > -- > Scala中文社区: http://groups.google.com/group/scalacn > > -- > You received this message because you are subscribed to the Google Groups > "Lift" group. > To post to this group, send email to lift...@googlegroups.com. > To unsubscribe from this group, send email to > liftweb+unsubscr...@googlegroups.com<liftweb%2bunsubscr...@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 Beginning Scala http://www.apress.com/book/view/1430219890 Follow me: http://twitter.com/dpp Surf the harmonics -- You received this message because you are subscribed to the Google Groups "Lift" group. To post to this group, send email to lift...@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.