2

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?

1 Answer 1

1

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.