简体   繁体   中英

How to keep StatefulSnippet var values when redirecting through Javascript

I have an image link that when i click it i want to do some changes in some class variables and then redirect to other page and use those values.

Here is my code, im using StatefulSnippet

class MySnippet extends StatefulSnippet {

  var selectedStudent: Student=null

  def students =
    ".tabla" #> studentsList.map { s =>
      "#id" #> s.Id &
      "#name" #> s.Name & 
      "#surname" #> s.Surname &
      "#buttonAcademic [src]" #> tickUrl &
      ".clickableAcademic [onclick]" #> SHtml.onEvent(onClickCallbackAcademic(s))
    }

  def onClickCallbackAcademic(student: Student,xhtml:NodeSeq)(s: String): JsCmd = {
    //makes some stuff to student
    selectedStudent = student
    JsCmds.RedirectTo("/Academic")
  }

}

But when I redirect to the other page, my var selectedStudent is null, i tried debugging and selectedStudent has the correct value but when redirecting it turns null. Any ideas?

StatefulSnippet using HTML form and hidden parameter to pass information (which snippet instance should be used) to server side of Lift.

So a JS redirect will not work, because it will not pass those information.

Here are some solution comes in my mind that may work in this case:

  • Wrapping a form outside of and submit it by JS in your onClickCallbackAcademic.

  • Instead of using StatefulSnippet, use SessionVar to store your selectedStudent, so you could use it without form submit.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM