playframework

Play Framework - Set URL for Assets

流过昼夜 提交于 2020-01-03 04:53:08
问题 In production, I want to use nginx for serving statics. How to set a URL for assets in Play framework that we can use in both development and production. I like the way Django set STATIC_URL in settings. EDIT: In Django, you can set STATIC_URL = 'https://static.domain.com/' in settings.py . In templates, you can call the value for: <script src='{{ STATIC_URL }}js/jquery.js'></script> 回答1: You can add anything you need to the application.conf, so for an instance it can be the static domain

Parse Json array response in scala\Play

人盡茶涼 提交于 2020-01-03 04:35:10
问题 There is a web service returning array of something {"apps": [{"name": "one"}, {"name": "two"}]} In my code I want to iterate every name val request = WS.url(s"http://localhost:9000/getData") val json = request.get.map { response => (response.json \ "apps" \\ "name") } json.foreach(println) However all my attempts return single record // Expect one two // Actual ListBuffer("one", "two") 回答1: First of all, the neat solution here would be: val request = WS.url(s"http://localhost:9000/getData")

how to pass sql array values from java controller to scala template

北慕城南 提交于 2020-01-03 04:35:07
问题 I am new to play framework. I want to pass array variables in java controller to scala template. try { String userName = "data"; String password = "data"; String url = "jdbc:mysql://localhost/playdb"; // Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver"); Connection con = DriverManager.getConnection(url, userName, password); Statement stmt = con.createStatement(); System.out.println("Connected database successfully..."); String strSelect = "select * from computer"; //statement

How to render JFreeChart in Play framework

有些话、适合烂在心里 提交于 2020-01-03 03:55:27
问题 Problem: does not allow me to renderBinary . The method renderBinary(InputStream) in the type Controller is not applicable for the arguments ( JFreeChart ). I have this controller: public static void index() { // create a dataset...Default DefaultPieDataset dataset = new DefaultPieDataset(); dataset.setValue("Category 1", 43.2); dataset.setValue("Category 2", 27.9); dataset.setValue("Category 3", 79.5); // create a chart... JFreeChart chart = ChartFactory.createPieChart( "Sample", dataset,

PlayRunHook does not work in multi module projects

给你一囗甜甜゛ 提交于 2020-01-03 02:24:35
问题 We need a base play framework projects which contains other play and scala projects as module. Those inner independent projects can have different javascript frameworks and build system like webpack, gulp, etc. So I tried the PlayRunHook from https://www.playframework.com/documentation/2.4.x/SBTCookbook . Single project hooking working as expected. But, unable to get it right on multi module project. Some code samples... Project Structure base/build.sbt name := """base""" version := "1.0

Play framework 2.2: How to get current controller and action in java

心不动则不痛 提交于 2020-01-02 22:34:19
问题 In my application authentication scheme is based on user and role. users with particular role have access to particular action method. To implement this I have done following 1.Write custom action public class Authorization extends play.mvc.Action.Simple { public Promise<Result> call(Context ctx) throws Throwable { //check access return delegate.call(ctx); } } 2.Annotate controller with action @With(actions.Authorization.class) public class Upload extends Controller { .... } In my action I

Include plain HTML page inside a Play Framework view template

放肆的年华 提交于 2020-01-02 20:08:22
问题 Is there a way to include a plain html page inside a Play Framework's view template? I have a scenario wherein there is a common view template and in the body of the template, I would like to include certain static html pages. I know that I can include other templates inside a certain template, but I'm not sure if I could include a plain html page? 回答1: One option is to just make your static HTML a template, eg, create myStaticPage.scala.html : <h1>Static page</h1> <p>This page is static,

Creating an Enumeratee from a stateful algorithm

蹲街弑〆低调 提交于 2020-01-02 09:56:30
问题 I have a stateful algorithm that incrementally takes input and incrementally produces output. The inputs and outputs are unrelated in number; i.e. an input may produce zero or more outputs. I am attempting to turn it into an Enumeratee in the Play Framework, but I am having difficulty getting started. My algorithm has local mutable state and synchronous operations and looks something like this var state = 'foo var i = input() while (i != null) { if (state == 'foo && i >= 0) { // 2 outputs,

Sending multi part form data in post method in play/scala

假装没事ソ 提交于 2020-01-02 08:55:59
问题 How can I send multi part form data in post method in play scala using : scalaVersion:2.11.7 playVersion-2.1.5 回答1: You need to do a little code, then you can use it like val data = MultipartFormData(formFields, "asdasboundarystringas") WS.url(myUrl).post(data.body) The code of MultipartFormData you can find on the github: https://gist.github.com/EECOLOR/7649144 UPDATE Another method, I have been try it with Play 2.4.3 package controllers import play.api.Play.current import play.api.libs.ws._

Sending multi part form data in post method in play/scala

风格不统一 提交于 2020-01-02 08:55:10
问题 How can I send multi part form data in post method in play scala using : scalaVersion:2.11.7 playVersion-2.1.5 回答1: You need to do a little code, then you can use it like val data = MultipartFormData(formFields, "asdasboundarystringas") WS.url(myUrl).post(data.body) The code of MultipartFormData you can find on the github: https://gist.github.com/EECOLOR/7649144 UPDATE Another method, I have been try it with Play 2.4.3 package controllers import play.api.Play.current import play.api.libs.ws._