David, That's what I thought. All I needed to do was create the Mapper.toForm like so:
item.toForm(Full("Save"), { _.save }) and the item would be saved on submit. But it doesn't work in my case. Glenn On Nov 20, 10:05 am, David Pollak <feeder.of.the.be...@gmail.com> wrote: > Glenn, > > All functions are bound to the current state in the scope that the function > was created. There's no need to do weird RequestVar things with Hidden > fields or anything else. If you've got a function passed to SHtml.text, > submit, etc. that function closes over its local scope: it captures all the > variables it refers to. > > So: > > def mySnippet = { > val myInstance = MyTable.find(whatever) > > SHtml.ajaxCheckbox(..., bool => {myInstance.boolField(bool).save; Noop}) > > } > > In the above code, you've captured the instance in the val myInstance... > that's kept around for the lifespan of the function that you passed to > ajaxCheckbox. > > Thanks, > > David > > > > On Fri, Nov 20, 2009 at 9:45 AM, glenn <gl...@exmbly.com> wrote: > > I've been following this thread as lately I'm having difficulty with > > an ajax-submitted > > request in my app. Here's the scenario (There's no simple way to > > describe this, so bear with me): > > > I create a JQuery tree of my data (Mapper object with just an item > > name and a parent Mapper object as it's fields) as follows: > > > def buildTree(in:NodeSeq):NodeSeq = { > > > object MyJqLoad { > > def apply(content: JsExp) = new JsExp with JQueryRight with > > JQueryLeft { > > def toJsCmd = JqId("json_result").toJsCmd + ".load(" + > > content.toJsCmd + JsRaw("""+this.id""") + ")" > > } > > } > > > val host = "http://" + S.hostName > > val link = host + ":8080" + S.contextPath + "/api/json/" + > > dbTableName.toLowerCase + "/" > > > val func = AnonFunc( MyJqLoad(link)) > > > TreeView("tree", JsObj(("persist", "location"), ("toggle", func)), > > loadTree, loadNode) > > } > > > The functions, loadTree and loadNode, are used to asynchronously > > build the tree of item names from the Mapper instances. > > The link val creates a URL, for example,http://localhost:8080/api/json/ > > <dbTableName>/, > > where dbTableName is just the Mapper object name. > > > On the client, the user clicks on a tree item, which, as you can see > > from the above code, submits the Mapper id selected to the server, > > which then > > pulls the Mapper.toForm html from the Mapper instance and returns it > > to the client at <div id="json_result"/>, which is in my template. > > This all works great. > > > Where this all breaks down, is in submitting the returned > > Mapper.toForm back to the server when I click on the "Save" button, > > because no Mapper instance > > exists at that point in the request or session for the save button to > > act on. > > > Somewhere, I'm thinking I have to modify the Mapper.toForm html so the > > submit button runs another JavaScript function on the client to return > > the Mapper id > > to the server for processing. But I haven't yet been able to do this. > > One of the problems is that I don't even have an id on the client > > (none is returned with Mapper.toForm > > html) to work with. And, it seems to me that to make this scenario > > work, I'm forced to become a JavaScript guru and work outside of Lift. > > In other words, if there isn't > > a mechanism in Lift to handle this situation directly, there should > > be. > > > One of the things I've tried is to add a hidden form field to the > > Mapper.toForm html, > > > SHtml.hidden(() => itemIdVar(id.toString)), > > > where itemIdVar extends RequestVar[String]. > > > But I couldn't make that work either. The hidden form field is suppose > > to run the ()=Any function, and it may do that, but not in the correct > > sequence to do any good > > when the form is submitted. > > > Glenn > > > On Nov 19, 11:35 pm, Jeppe Nejsum Madsen <je...@ingolfs.dk> wrote: > > > Chris Lewis <burningodzi...@gmail.com> writes: > > > > Thanks for the feedback Jeppe. I can't completely infer the context of > > > > your example, > > > > Seems to happen a lot to me lately. :-) This was just a quick paste from > > > our codebase.... > > > > > but I get the idea (and I hadn't known about TemplateFinder). Here's > > > > what I've hacked together so far. > > > > /Jeppe > > > -- > > > 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=. > > -- > Lift, the simply functional web frameworkhttp://liftweb.net > Beginning Scalahttp://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=.