On Mon, Jul 13, 2009 at 1:32 PM, Peter Robinett <[email protected]>wrote:

>
> Thanks guys, I happened to be looking for this right now.
>
> For those looking to output single Boxed result from findAll, I think
> you would do something like this:
> JsonResponse(JsObj("results" -> Node.find(By(Content.id,
> yourIdQuery)).openOr(Content).asJs))





>
>
> The problem is that if the Content row isn't found you get a result
> based upon the companion object. Is there a way to give a truely empty
> JsObj when there isn't a Full Box?


Content.find(id).map(_.asJs).openOr(JsNull)

>
>
> I have a few additional questions based upon JsonResponse. Why not use
> asJSON instead of asJs? Is this because JsonResponse requires as
> JsExp? When would it be recommended to use asJSON and its String
> return value?


String is evil.  Keep things as type safe as possible for as long as
possible.  If you convert to a String early, there's no benefit and lots of
costs.

I've removed the asJSON method from the meta mapper.



>
>
> Also, I notice that the JsExp produced by calling asJs on a model
> includes '$lift_class': 'nodes'. People might not want to expose that
> in their final JSON output...


You can override the behavior of asJs(node: Node) in your metamapper and
remove the "$lift_class" part.

Thanks,

David


>
>
> Peter
>
> On Jul 13, 12:15 pm, David Pollak <[email protected]>
> wrote:
> > On Mon, Jul 13, 2009 at 11:42 AM, fbettag <[email protected]> wrote:
> >
> > > JsonResponse(JsObj("results" -> JsArray(Content.findAll.map{ o =>
> > > o.asJs } :_* )))
> >
> > > this works.
> >
> > Great!
> >
> >
> >
> >
> >
> > > On Jul 13, 8:08 pm, fbettag <[email protected]> wrote:
> > > > WebServices.scala:118: error: type mismatch;
> > > >  found   : net.liftweb.http.js.JsExp
> > > >  required: Iterable[net.liftweb.http.js.JsExp]
> > > >                 JsObj("results" ->
> > > JsArray(Content.findAll.flatMap(_.asJs) :_* ))
> > > >
>  ^
> > > > one error found
> >
> > > > On Jul 13, 7:23 pm, David Pollak <[email protected]>
> > > > wrote:
> >
> > > > > On Mon, Jul 13, 2009 at 10:11 AM, fbettag <[email protected]> wrote:
> >
> > > > > > i've read almost every topic about JsonResponse and i've played
> with
> > > > > > it for the _whole_ day. I don't get it to work and it drives me
> more
> > > > > > than nuts by now.
> >
> > > > > > I just want a simple list dumped to json:
> >
> > > > > >        def listContents(): JsonResponse = {
> > > > > >                JsonResponse(JsObj("results" ->
> > > > > > JsExp(Content.findAll.flatMap
> > > > > > (_.asJs))))
> > > > > >        }
> >
> > > > > JsExp is abstract, so you can't instantiate one.
> >
> > > > > If the results field should be a JsArray, use:
> >
> > > > > JsObj("results" -> JsArray(Content.findAll.flatMap(_.asJs) :_* ))
> >
> > > > > > that was my final try. parts like this really need
> documentation.. by
> > > > > > all means, my scala skill really isn't one of the things i can be
> > > > > > proud of (yet), but getting sense out of those abstract docs is
> > > really
> > > > > > more than hard.
> >
> > > > > > best regards.
> >
> > > > > --
> > > > > Lift, the simply functional web frameworkhttp://liftweb.net
> > > > > Beginning Scalahttp://www.apress.com/book/view/1430219890
> > > > > Follow me:http://twitter.com/dpp
> > > > > Git some:http://github.com/dpp
> >
> > --
> > Lift, the simply functional web frameworkhttp://liftweb.net
> > Beginning Scalahttp://www.apress.com/book/view/1430219890
> > Follow me:http://twitter.com/dpp
> > Git some:http://github.com/dpp
> >
>


-- 
Lift, the simply functional web framework http://liftweb.net
Beginning Scala http://www.apress.com/book/view/1430219890
Follow me: http://twitter.com/dpp
Git some: http://github.com/dpp

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Lift" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/liftweb?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to