Sunday 15 March 2015

Using scala and java in play framework 2.1 : Session usage -


I am currently using session () of the play framework in my template: / P>

  @if (session (.) ("Email") == Get tap {{lt; li & gt; & lt; a href = "@controllers.products.general.login" & Gt; Login & lt; / a & gt; & lt; / li & gt; Other { li & gt; & lt; a href = "@ Controllers. Products. General logout" & gt; Logout & Lt; / a & gt;   

This template is used in all my thoughts. Some of these scenes are not a Java Controlled by the device, and some scala are with the controller.

When I click on the link which leads the Java controllers, then I have no problem, the link to login and Logout is correct handled.

When I click on the link which leads to Scala Controllers, I get a [[Code> Runtime Express: here is no HTTP reference.]

Scala Controllers In Are I here that read, I understood that he did not return when Acteepi reference to the presentation page, but I really want to be able to use the sessions in your template.

I thought about using a logic in my approach, templates and controllers about session () , but I believe that Java session (play.mvc.http.session ) And the skalization session (play .api.mvc.seession) when the game will compile html pages.

Am I stuck? Are there any chances to force Scala controllers to return the HAK reference? The original reason probably is that Java controllers and scala controllers are controlled separately.

My project is first in my Java, and then try to add more scala controllers I also came in this problem (using BTW, I am using 2.3.2).

I used my own ActionBuilder to retrieve my own HTML in TheadLocal variable. Tried to fix this by setting up the contact.

  Import play.api.mvc._ import scala.concurrent.Future import play.mv.Http.Context Import play.core.j.JavaHelpers Object ContextAction ActionBuilder extension [request] { Def invokeBlock [A] (Request: Request [A], Block: (Request [A]) = & gt; future [result] = {reference Content.set (JavaPrintService JavaContact (Requests)) Block (Requested)}}   

Then use this reference instead of my Scala Controller functions:

  extension of class testcontroller controller {def test = ContextAction {root request = & gt; Ok (views.html.index ())}}   

and thus the index template can use all the requests () / sessions () / etc.

No comments:

Post a Comment