playframework-2.0

Playframework scala howto create temp variable

杀马特。学长 韩版系。学妹 提交于 2020-01-13 04:28:08
问题 Hi So I have a while loop: @for(i <- 0 until consoles.size) { ... Do something ... Add records to a column } But what I would like to add a variable and depending on what is going on add it to a different group. For example: @var column = 0; @for(i <- 0 until consoles.size) { @if(consoles[i].groupname != consoles[i - 1].groupname) { column = column + 1; } ... Do something ... Add records to a column } Is this possible. The only thing I have found is by passing in a variable and using that but

How do you get the size of a Request in Play 2.0.x?

谁都会走 提交于 2020-01-13 03:11:45
问题 In Play Framework 2.0.3 (scala), how do you determine the size (in bytes) of any Request[_]? We're trying to obtain this information for logging purposes. We would expect some value from request.body.asRaw, but we always obtain None: def logRawRequest[A](request: Request[A]) { request.body match { case c: AnyContent => println("Raw: "+c.asRaw) } } There must be something simple that we're missing, right? Thanks for the helpful answers! It turns out that the Content-Length header is only

Play Framework — add new directories to classpath

五迷三道 提交于 2020-01-12 08:33:09
问题 I would like to be able to have a separate directory where jar files that represent plugins can be added to a Play 2.0 project. Jar files are normally kept under the /lib directory in Play. I'd like to separate my jars in a directory called /plugins This question was asked before, but the suggestion was to just use the /lib directory. Adding additional java files to playframework classpath Is there no way to do this without manually changing the 'eclipsified' files generated by Play? 回答1: I

Use @JsonView to exclude (like @JsonIgnore) with play frameworks default json writer?

寵の児 提交于 2020-01-11 11:34:09
问题 It seems you can't mix @JsonIgnore and @JsonView. I want to hide a field by default, but show it in some cases. Basically I've got this setup :- class Parent extends Model { public Long id; public Child child; } class Child extends Model { public Long id; @JsonView(Full.class) public String secret; public static class Full {}; } And want to use play.libs.Json.toJson(parent) to render WITHOUT child.secret, and ObjectMapper objectMapper = new ObjectMapper(); ObjectWriter w = objectMapper

How to send a file to browser for downloading?

别说谁变了你拦得住时间么 提交于 2020-01-11 02:18:06
问题 When client request for a file, I use this code to send it: public static Result download(String file) { File file = getRealFile(file); return Ok(file); } But I found the browser will not download it, but display its content instead. The response header: Content-Type text/plain Transfer-Encoding chunked What's the correct way to send a file? Update Per Razvi's answer, I found an answer seems good for this question: https://stackoverflow.com/a/1074925/342235 But do we really have to set so

Running Play Framework 2.0 on Tomcat?

浪子不回头ぞ 提交于 2020-01-10 17:45:56
问题 I can't find any information about deploying Play Framework 2.0 on Tomcat, is it even possible? If so, where can I find any info regarding it. 回答1: Sadly, it is not supported in the Play 2.0 release. Looks like the feature got pushed to 2.1, here is the the ticket. Update There is a plugin that aims are war support for Play 2: https://github.com/dlecan/play2-war-plugin/ 回答2: The Asynchronous IO model is not supported by Servlet 3.0 containers. See post by one of the committers below: "We are

How to manipulate Session, Request and Response for test in play2.0

删除回忆录丶 提交于 2020-01-09 22:10:21
问题 Hi I had an authentication service which works on Request (some Header-Data and Cookie), Response (to set or delete a cookie) and session (Store userId and rememberMe-information). In play 1.x it was easy to fake Request, Response, Cookie and Session. It could be easily set with Session.current().set(new Session()) . In play 2.0 this doesn't work anymore. How can I add a cookie to a request? How could I manipulate the session? I saw there exists FakeApplication and FakeRequest but I didn't

How to manipulate Session, Request and Response for test in play2.0

只谈情不闲聊 提交于 2020-01-09 22:10:02
问题 Hi I had an authentication service which works on Request (some Header-Data and Cookie), Response (to set or delete a cookie) and session (Store userId and rememberMe-information). In play 1.x it was easy to fake Request, Response, Cookie and Session. It could be easily set with Session.current().set(new Session()) . In play 2.0 this doesn't work anymore. How can I add a cookie to a request? How could I manipulate the session? I saw there exists FakeApplication and FakeRequest but I didn't

How do I configure Logback to print out the class name

无人久伴 提交于 2020-01-09 10:37:52
问题 I'm using Play 2.1. I'm using the default logger play.api.Logger. I'm confused about how it works. In my scala code, a line in class "com.myapp.tickets" in the method "getPayment()" like this Logger.info("getTickets") generates a log message like this. 14:58:58.005 INFO application play.api.LoggerLike$class info getTickets My application-logger.xml pattern is %d{HH:mm:ss.SSS} %-5level %logger %class %method %msg%n The issue I have is that %logger tells me "application", %class tells me "play

Play Framework WS losing unicode chars from external api

♀尐吖头ヾ 提交于 2020-01-07 05:01:27
问题 I'm working on a play application that uses WS to make an asynchronous call to an external api and I can't figure out why I'm losing unicode chars when consuming for instance if they api is producing something like: { "title": "Plück, Franke" } and make a call to the api with: ws.url("http://example.org/stuff/").get().map { response => println(response.body) Ok.... The following will print: { "title":"Plück, Franke" } I'm trying to find if there is a header argument that I need to be passing