Skip to content

Add helpers to snapshot and pass objects in request parameters #978

Closed
indrajitr opened this Issue Apr 17, 2011 · 2 comments

3 participants

@indrajitr
Lift Web Framework member

Accordingly to discussion [[url:https://groups.google.com/d/topic/liftweb/vPkJ9m0SqlI/discussion|Passing objects with RequestVar via GET request]]

dpp:
Personally, I'd do this with RequestVars rather than with SessionVars because that gives you scope over the variables (they're good for the scope of a single request rather than for the entire session).

So, if you've got a couple of RequestVars, you can do the following:

    object rv1 extends RequestVar...
    object rv2 extends RequestVar...

    def snapshot(): () => Unit = {
      val v1 = rv1.get
      val v2 = rv2.get
      () => {rv1.set(v1); rv2.set(v2)}
    }

    def buildCallbackURL(baseURL: String): String = S.fmapFunc(snapshot())(key => Helpers.appendFuncToURL(baseURL, key +"=_"))

The snapshot method creates a function that will restore the RequestVars to the state that they had when it was called. The buildCallbackURL method takes a base URL (built using whatever mechanism you choose) and appends the restore function to it. When that URL is hit on the server, the RequestVars will be restored and away you go.

nafg:
Neat code! Maybe it would be useful to have a generalization in the library?
1. def snapshot(rvs: RequestVar*): ()=>Unit
2. def urlWithState(baseUrl: String, state: ()=>Unit)

@dpp
Lift Web Framework member
dpp commented May 15, 2011

(In [[r:614098d4098bd6ce89e529f8638e877b440be92c]]) Closes #978. Added snapshot capability to RequestVar and allow RequestVar to be put in groups and snapshotted as a group

Branch: master

@dpp dpp was assigned Mar 1, 2012
@etorreborre etorreborre pushed a commit to etorreborre/framework that referenced this issue Dec 3, 2014
@dpp dpp Closes #978. Added snapshot capability to RequestVar and allow Reques…
…tVar to be put in groups and snapshotted as a group
614098d
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.