Unfortunately this did not solve my problem :

Let me paste the complete code :

Client View :

object ViewClient extends ViewClient
{
  object currentClient extends RequestVar [Box [Client]] (Empty)
}

class ViewClient
{
  val clientId = S.param ("id") openOr ""

  val client = try {
    Client.findByKey (clientId.toLong)
  }
  catch {
    case e:NumberFormatException => Empty
  }

  def view (inhtml: NodeSeq) : NodeSeq = {

    client map ( { c =>
      bind ("client", inhtml,
            "firstName" -> c.firstName.asHtml,
            "lastName" -> c.lastName.asHtml,
            "addInvoice" -> SHtml.link ("/invoice/create", () =>
ViewClient.currentClient (Full (c)), Text ("Ajouter Facture")))
               } )  openOr Text ("Client invalide")

  }
}

AddInvoice View : (linked to /invoice/create)

class AddInvoice {

  def add (inhtml: NodeSeq) : NodeSeq = {

    val inInvoice = Invoice.create
    val clientBox = ViewClient.currentClient
    val client = ViewClient.currentClient.open_!

    def processEntry () {
      S.notice ("Test " + client.firstName)
      clientBox map (inInvoice.client (_))
      inInvoice.save
      S.notice ("Entre : Description " + inInvoice.description + "
Montant : " + inInvoice.amount)
    }

    bind ("e", inhtml,
          "description" -> inInvoice.description.toForm,
          "amount" -> inInvoice.amount.toForm,
          "submit" -> SHtml.submit ("Ajouter Facture",  processEntry))
  }
}

This yeilds an empty box exception...

The method suggested by Naftoli Gugenheim does the same .. it seems
the is does not "copy" the value either...

So in both cases whatever was in my RequestVar is gone on the second
request...


Any ideas ?

Thanks!

hexa

On Mar 9, 3:09 pm, David Pollak <feeder.of.the.be...@gmail.com> wrote:
> Howdy,
>
> Lift does rendering most basically with Snippets.  Snippets are functions
> NodeSeq => NodeSeq... they take a NodeSeq and return a NodeSeq.  Snippets
> are generally independent entities.  They do not know about each other.
>  They can ask about the state of the session and the state of the request.
>
> We introduced RequestVar (and SessionVar) to give developers a type-safe way
> to share information during the scope of a request (RequestVar) and session
> (SessionVar).
>
> RequestVars are strongly typed.  That means if you define a RequestVar to
> hold a String, the compiler will not allow you to put a List into it.
>
> Behind the scenes, RequestVars use a shared Map[String, Any] to store the
> information.  The String is the "name" of the RequestVar and the Any is the
> thing that you are putting into the slot for the Var.
>
> So, we use a little "magic" to generate the unique but stable name of the
> Var.  Specifically, we look at the class name that the compiler selected for
> the object that extends RequestVar.  If the object is defined within a
> class, the class name for the RequestVar will depend on that class name.
>  When you have an object that extends a class, the Scala compiler may
> generate a new class and thus your "currentClient" RequestVar in the
> ViewClient class and the ViewClient object are different RequestVars.  They
> point to different things.
>
> The easiest way to deal with this is to make your currentClient a top-level
> object.  If you want to scope the currentClient RequestVar someplace, I'd
> suggest:
>
> object ViewClient extends ViewClient {
>   object currentClient extends RequestVar...
>
> }
>
> So, please try putting the currentClient someplace where there's a single
> path (from a class perspective) to it and I'm guessing that your issue will
> go away.
>
> Thanks,
>
> David
>
>
>
> On Mon, Mar 8, 2010 at 10:13 PM, hexa <hex...@gmail.com> wrote:
> > Hi,
> >  I have a RequestVar that I send to a snippet which will then do a
> > post...
>
> > But I would like the RequestVar to persist between the moment it it
> > received in the post snippet and the post itself...
>
> > The only way I found of doing it right now is like :
>
> > Source Snippet :
>
> > object ViewClient extends ViewClient
>
> > class ViewClient
> > {
> >  object currentClient extends RequestVar [Box [Client]] (Empty)
>
> > bind  (...
> >  "addInvoice" -> SHtml.link ("/invoice/create", () => currentClient
> > (Full (c)), Text ("Ajouter Facture")))
>
> > Destination Post Snippet :
>
> > def add (inhtml: NodeSeq) : NodeSeq = {
>
> >    val inInvoice = Invoice.create
> >    val clientBox = ViewClient.currentClient
>
> >    val client_id = clientBox map (_.id.toLong)
>
> >    def processEntry () {
> >      Client.findByKey (client_id openOr 0) map (inInvoice.client (_))
> >      inInvoice.save
> >      S.notice ("Entre : Description " + inInvoice.description + "
> > Montant : " + inInvoice.amount)
> >    }
>
> > bind ("e", inhtml,
> >          "description" -> inInvoice.description.toForm,
> >          "amount" -> inInvoice.amount.toForm,
> >          "submit" -> SHtml.submit ("Ajouter Facture",  processEntry))
>
> > If I try to access the clientBox in processEntry, even with the
> > closure it should generate.. I get an empty box...
>
> > Is there any way to copy / ref or anything or make a new RequestVar
> > with a copy of the preceding one ?
>
> > Would have been nice not to be obligated to do the client_id toLong
> > code...
> > And juste do inInvoice.client (client)  , inInvoice.save
>
> > Thanks a lot
>
> > hexa
>
> > --
> > 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 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=en.

Reply via email to