(1) Don't use open_! unless you have a very, very, very good reason to do
so.  It defeats the purpose of Box.
(2) If you have a particular question/example of what you want to do (a
complete, runnable example), I can work out a pattern for you.

On Mon, Aug 10, 2009 at 8:37 AM, Jeppe Nejsum Madsen <[email protected]>wrote:

>
> Hi,
>
> I'm using CRUDify, but all domain objects belong to an account, so I
> need to add the current user's account id to the queries made by
> CRUDIfy. This works fine for the list Loc:
>
> override def findForListParams: List[QueryParam[Vehicle]] =
>      List(OrderBy(primaryKeyField, Ascending), By(account,
> User.currentUser.open_!.account.is))
>
> But for the edit/delete Locs, this fails:
>
>  override def findForParam(in: String): Box[Vehicle] = {
>    Log.info("User %s, id=%s".format(User.currentUser, User.currentUserId))
>    find(List(in,By(account, User.currentUser.open_!.account.is)))
>  }
>
> Both currentUser & currentUserId is empty at this point in the request
> cycle, as can be seen from this log output:
>
> INFO - User Empty, id=Empty
> java.lang.NullPointerException: Trying to open an empty Box
>        at net.liftweb.util.EmptyBox.open_$bang(Box.scala:370)
>        at net.liftweb.util.EmptyBox.open_$bang(Box.scala:366)
>        at dk.model.Vehicle$$$M$f617a4a2.findForParam(Vehicle.scala:276)
>        at dk.model.Vehicle$$$A$f617a4a2.findForParam(<generated>)
>        at dk.model.Vehicle$.findForParam(Vehicle.scala:259)
>        at
> net.liftweb.mapper.CRUDify$$anon$6$$anonfun$4.gd4$1(CRUDify.scala:174)
>        at
> net.liftweb.mapper.CRUDify$$anon$6$$anonfun$4.isDefinedAt(CRUDify.scala:170)
>        at
> net.liftweb.mapper.CRUDify$$anon$6$$anonfun$4.isDefinedAt(CRUDify.scala:170)
>        at
> net.liftweb.util.NamedPF.isDefinedAt(NamedPartialFunction.scala:29)
>        at
> net.liftweb.sitemap.Loc$$anonfun$rewritePF$1$$anon$1.isDefinedAt(Loc.scala:77)
>        at
> net.liftweb.sitemap.Loc$$anonfun$rewritePF$1$$anon$1.isDefinedAt(Loc.scala:70)
>        at
> net.liftweb.util.NamedPF$$anonfun$find$1.apply(NamedPartialFunction.scala:51)
>        at
> net.liftweb.util.NamedPF$$anonfun$find$1.apply(NamedPartialFunction.scala:51)
>        at scala.List.find(List.scala:1048)
>        at net.liftweb.util.NamedPF$.find(NamedPartialFunction.scala:51)
>        at net.liftweb.util.NamedPF$.applyBox(NamedPartialFunction.scala:91)
>        at net.liftweb.http.Req$.processRewrite$1(Req.scala:114)
>        at net.liftweb.http.Req$.apply(Req.scala:123)
>        at
> net.liftweb.http.provider.HTTPProvider$class.service(HTTPProvider.scala:51)
>        at net.liftweb.http.LiftFilter.service(LiftServlet.scala:481)
>        at
> net.liftweb.http.provider.servlet.ServletFilterProvider$class.protected$service(ServletFilterProvider.scala:41)
>        at
> net.liftweb.http.LiftFilter.protected$service(LiftServlet.scala:481)
>        at
> net.liftweb.http.provider.servlet.ServletFilterProvider$$anonfun$doFilter$1.apply(ServletFilterProvider.scala:41)
>        at
> net.liftweb.http.provider.servlet.ServletFilterProvider$$anonfun$doFilter$1.apply(ServletFilterProvider.scala:36)
>        at
> net.liftweb.http.RequestVarHandler$$anonfun$apply$5$$anonfun$apply$6$$anonfun$apply$7$$anonfun$apply$8.apply(Vars.scala:212)
>        at net.liftweb.util.ThreadGlobal.doWith(ThreadGlobal.scala:65)
>        at
> net.liftweb.http.RequestVarHandler$$anonfun$apply$5$$anonfun$apply$6$$anonfun$apply$7.apply(Vars.scala:211)
>        at net.liftweb.util.ThreadGlobal.doWith(ThreadGlobal.scala:65)
>        at
> net.liftweb.http.RequestVarHandler$$anonfun$apply$5$$anonfun$apply$6.apply(Vars.scala:210)
>        at net.liftweb.util.ThreadGlobal.doWith(ThreadGlobal.scala:65)
>        at
> net.liftweb.http.RequestVarHandler$$anonfun$apply$5.apply(Vars.scala:209)
>        at net.liftweb.util.ThreadGlobal.doWith(ThreadGlobal.scala:65)
>        at net.liftweb.http.RequestVarHandler$.apply(Vars.scala:208)
>
> I think I'm seeing something similar to the problem mentioned here
>
> http://groups.google.com/group/liftweb/browse_thread/thread/0190091bcdb6d18a/90a33ace15273d3d?lnk=raot
>
> except now also the User.currentUserId SesssionVar seems to be
> uninitialized.
>
> So, is this not supported? Is there a workaround?
>
> Just back from two weeks of vacation, I might have missed something
> obvious :-)
>
> /Jeppe
>
> >
>


-- 
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