Ich bin neu im Framework zu spielen. Im angegebenen Code wird activing/connect mit salesforce verbunden und zu/getObjects umgeleitet, aber nach der Umleitung wird die Salesforce-Verbindungsvariable "x" wieder null.Variablen werden nach der Umleitung zurückgesetzt [SCALA-PLAY]
package controllers
import play.api.mvc.{Action, Controller}
class ApplicationController extends Controller {
var x:connectBase = null
def connect(uname: String, pwd: String) = Action {
val con = SalesForceDump(uname, pwd)
con.connect
if (!con.isConnected) {
Ok("error")
}
else {
x = connectBase(con)
Ok("user:").withSession("connected" -> uname)
Redirect(routes.ApplicationController.getObjects)
// Ok("done")
}
}
def getObjects = Action { request =>
println(x.connection) // this gets null
request.session.get("connected").map { user =>
println("Hello " + user)
Ok(x.connection.getAllObjects.mkString(","))
}.getOrElse {
Unauthorized("Oops, you are not connected")
}
}
}