Reference on redirectto and referer

31 views
Skip to first unread message

Philippe Derome

unread,
Nov 9, 2015, 8:46:29 AM11/9/15
to Lift
Do you have best tutorial or doc that goes into usage of those in some depth?

I have an artificial contrived cose sample that uses it wrong and will move on to more lift easy tutorials so my would be example may not make sense. Better ways to use the framework may make my immediate issue irrelevant.

I have 2 Ajax forms, 1 snippet for each, ProducerSnippet captures data, submits async fine on user button click. User clicks on button of form2 in ConsumerSnippet, stores state in SessionVar and does redirect (similar to some of first examples of easy lift).

The 2 snippets are Object in Scala.

Snippet1 is then properly rendered, which is similar to some extent to AjaxExample 4.8 of EasyLift (transforming classic form to Ajax). Then user reenters form datain ProducerSnippet and submits again. That's where the symptom of problem occurs.

At this point async callback process fires exactly once correctly but the anonymous function for Redirectto fires twice and so I see double entries in menu for S.notice. I expected and wish for the anonymous function to be called only once. In fact it fires N times where N is 1+ number of times I submit ConsumerSnippet form.

So I am probably setting up variables whence incorrectly in the 2 forms or something else is going on.

If need be, I can attach code but for now I am more interested in right background documentation so I can solve problem on my own.

Phil

Brett Grace

unread,
Nov 9, 2015, 11:46:47 AM11/9/15
to Lift
I'd like to help, but I don't have enough experience with Lift to create a mental model of what's going on here. If you post some code and we find the issue, it will be much easier to point you to the relevant discussion.

Philippe Derome

unread,
Nov 9, 2015, 6:45:50 PM11/9/15
to Lift
I found the error a few minutes after my post and verified it in code once I got home.

Basically in code as follows, I introduced web server side code that does not belong instead of pure constructs converting to JavaScript.

Mine after fix:

RedirectTo(whence, () => {
S.notice("Store:" + store)
  // Garbage unwanted irrelevant code removed (going to do a client http get call)
if (prod.isDefined) {
S.notice(
"Product Name:" + prod.get.name)
}
else {
Noop
}

Corresponding Easy-Lift AjaxExample 4.8 http://simply.liftweb.net/index-4.8.html#prev (his case Full(a) => RedirectTo corresponds to my code above).

   def process(): JsCmd= {
      // sleep for 400 millis to allow the user to
      // see the spinning icon
      Thread.sleep(400)
       
      // do the matching
      asInt(age) match {
        // display an error and otherwise do nothing
        case Full(a) if a < 13 => S.error("age", "Too young!"); Noop
        // redirect to the page that the user came from
        // and display notices on that page
        case Full(a) => {
          RedirectTo(whence, () => {
            S.notice("Name: "+name)
            S.notice("Age: "+a)
          })
        }
         
        // more errors
        case _ => S.error("age", "Age doesn't parse as a number"); Noop
Reply all
Reply to author
Forward
0 new messages