w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
play framework anorm for different database
Short answer: NO. Long answer: Anorm is just a library for dispatching your SQL queries to the database through JDBC, retrieving the results and delivering them to you. It does not understand the differences between different databases because it relies on JDBC for connection handling, and on you for writing queries. You either have to handle different DB engines yourself or have an ORM handle that for you. PS: Unless you really need to have a DB agnostic application (and fully understand its implications), I'd suggest you simply target 2-3 popular engines and avoid the future complications.

Categories : Scala

Play Framework 1.2.6 connect multiple database
Play 1.2.6 (or the 1.2.x branch) doesn't support multiple database connections out of the box. This support will be available in Play 1.3 which has not been released yet. Here is the according ticket from the Play bug tracker: http://play.lighthouseapp.com/projects/57987-play-framework/tickets/706

Categories : Java

How to display a database columns using CRUD in play framework?
I assume you want to do this in your application code in runtime. You can execute query using DB plugin to search DB metadata using native PostgreSQL queries. Here's an example how to get column names of my system DOCUMENT table: List<String> columns = new ArrayList<>(); ResultSet result = DB.executeQuery("select column_name from INFORMATION_SCHEMA.COLUMNS where table_name = 'DOCUMENT';"); while(result.next()) { String column = result.getString(1); columns.add(column); } This note that code is somewhat simplified and you should use prepared statements if anything in this query will be inserted from data that user or any other system entered. Use DB.getConnection().prepareStatement() to get PreparedStatement instance.

Categories : Java

Using play framework and scala how to display image path from database
You can put some methods on your controller just like this. I have a controller Profile and I added a method getImage(string id) to return the photo of the person from db... public class Profile extends Controller { public static void getImage(String id) { models.Person person = models.Person .findById(id); if(person.photo!=null) { ByteArrayInputStream input = new ByteArrayInputStream(person.photo); renderBinary(input); return; } VirtualFile vf = VirtualFile.fromRelativePath("/public/images/no_photo.jpg"); File f = vf.getRealFile(); renderBinary(f); } } on your View, you can use <img src=@{Profile.getImage(person.id)}> Ho

Categories : Scala

how to display image( as image path ) from database in play framework
Assuming your image is saved in public/images/ and the path saved in your database is images/image.jpg, you can simply pass the path to your view and use the router to resolve the image: @(path : String) <img src="@routes.Assets.at(path)" /> In the end this will give you the following HTML: <img src="/assets/images/image.jpg" /> (you can verify this by looking at the source code of the generated HTML page, ctrl - u in Firefox) The assets folder is where Play puts all the images from the public/images directory.

Categories : Scala

Running Play framework 2.1.1 and getting "exception when typing play.Project.javaCore"
Ok so in the end I had to delete the repository cache - I'm guessing it'd got corrupted somehow. Which would explain why it was complaining about not being able to find some class files. Another possibility about why it stopped working may be due updates to java itself. There had been at least one update to java (to 1.7.0_25 on ubuntu) since I last tried running play, so there may have been some issue there (perhaps minor binary class file change?). My play folder is in my home directory, so I did the following: $ cd ~/play-2.1.1/ $ rm -r repository/cache/ Then tried running play again inside one of the sample app folders. It took a while (presumably as it was rebuilding the cache) and then worked.

Categories : Java

How can I use Play Framework's FakeApplication to stub out calls to web services via play's WS object?
You could create a structural type that mimics the WS signature and use that in your code. type WSLike = { def url(url: String): WSRequestHolder } Then you can inject your own version of a WSLike class. In combination with a mock library I guess you could do about anything you want. As for the second question. You could call it like this: val url = Play.current.configuration .getString("my.webservice.url") .getOrElse(throw new PlayException( "Configuration error", "Could not find my.webservice.url in settings")) WS.url(url) Then in your application.conf add the correct url. You can supply a different one using the FakeApplication. FakeApplication(additionalConfiguration = Map("my.webservice.url" -> "http://localhost/service"))

Categories : Web Services

Play Framework 2.1.1 cannot find play object in multi-project setup Build.scala
Are you sure the Play plugin is correctly loaded ? Without it, the Play library cannot be used in the Build file (or anywhere else). As explained here, the project/plugins.sbt file must contain the plugin definition. You can look at these samples to have working examples of this file: // The Typesafe repository resolvers += "Typesafe repository" at "http://repo.typesafe.com/typesafe/releases/" // Use the Play sbt plugin for Play projects addSbtPlugin("com.typesafe.play" % "sbt-plugin" % Option(System.getProperty("play.version")).getOrElse("2.0"))

Categories : Scala

Play Framework - Is it posible to combine use of Promise and WebSocket in Play?
I do not believe you can use a promise with a web socket. However, you can use Akka to execute a task in the background. For example, the following code should let Akka handling the longer operation (database query) in the background: public static WebSocket<String> webSocket() { return new WebSocket<String>() { public void onReady(final WebSocket.In<String> in, final WebSocket.Out<String> out) { in.onMessage(new F.Callback<String>() { public void invoke(String event) { Akka.system().scheduler().scheduleOnce( Duration.Zero(), new Runnable() { public void run() { String result =

Categories : Java

How to do Play Framework with AngularJS e2e testing or with Play testing
Please be a little bit more precise about "proper behaviour". What is the bug ? Is the problem about integrating e2e tests with the Play workflow or just having e2e AngularJS green instead of red ? The difficulty here is to define "End-to-end" since there is no good definition of it, in wikipedia there is no mention about it. You can have have a good idea of what it is just because it is self-speaking, and there is also a excellent thread about end-to-end here : http://www.geekinterview.com/question_details/40319 So let's say that you want to test all scenarios with Front + Back in a close-to-prod environment. End-to-end testing AngularJS is supposed to be done with Karma, but, warning, it will be soon changed by ProtractorJS. Doing e2e test with Karma has serious drawbacks : It may

Categories : Javascript

Play framework 2.1.x and EbeanServer
Try running your test code inside a fakeApplication(): import ... import play.test.Helpers.*; public class TestSomeModel extends BaseModelTest { @Test public void myModelCreate() { running(fakeApplication(), new Runnable() { public void run() { SomeModel model = new SomeModel(); model.someStringAttribute = "some value"; assertThat(model.id).isNull(); model.save(); assertThat(model.id).isPositive(); } } } }

Categories : Java

getting the value of a checkbox in play framework
From what I can understand of your question, in simple Javascript: if(checkBoxDetails.checked){...} or even if(checkBoxDetails.checked == true){...}

Categories : Twitter

How to run a JPA Query in Play Framework 1.2.5
You have to import the Query class. import javax.persistence.Query; Doesn't your IDE flag such errors? SHouldn't you be able to fix basic compilation errors before using Play and JPA? Start by learning the basics of Java. Also, select * from Book is not JPQL. select b from Book b is.

Categories : Java

Play framework 2.1 with Spring
Play has it's own way of managing REST, transactions (depending on the JPA library used) and interceptors. You can integrate it with Spring, see this demo in github, but I'd first think about if you really need it.

Categories : Spring

Play Framework MVC mailer
That's easy. You can just call addRecipient multiple times to add more recipients. Or you can pass multiple recipients to it, like this: addRecipient("alice@example.com", "bob@example.com", "charlie@example.com"); Or you can pass an array to addRecipient: String[] rcpts = new String[] {"alice@example.com", "bob@example.com"}; addRecipient(rcpts); Or you can take a List, make an array from it, and then pass it: List<String> rcptsList = new ArrayList<String>(); rcptsList.add("alice@example.com"); rcptsList.add("bob@example.com"); addRecipient(rcptsList.toArray(new String[rcptsList.size()]));

Categories : Java

Enforcing SSL in Play! Framework 2.1.3
This is super easy with Play 2.2, not sure it works on 2.1.3, I didn't see it in the 2.1.x docs...but was in the 2.2.x docs...so give it a shot, it might be implemented. Throw this in your configuration file : http.port=disabled Or you could run it with the command line option : -Dhttp.port=disabled http://www.playframework.com/documentation/2.2.x/ConfiguringHttps

Categories : Ssl

Autofilling a form using the Play Framework
The documentation says something about it http://www.playframework.com/documentation/2.2.x/ScalaForms - scroll down to "Fill values" val userForm = userForm.fill(User("Bob", 18))

Categories : Forms

Play framework input without label
I guess you would need to write your own field constructor, eg: @(elements: helper.FieldElements) <div class="@if(elements.hasErrors) {error}"> <div class="input"> @elements.input <span class="errors">@elements.errors.mkString(", ")</span> <span class="help">@elements.infos.mkString(", ")</span> </div> </div> More info here: http://www.playframework.com/documentation/2.0/JavaFormHelpers

Categories : Java

Theming support in Play Framework 2.0
You have to implement it yourself, as a reference, check the Play Authenticate usage sample, it allows to send ie. validation emails basing on Play's template and depending on the client's language, so for an instance, if your main language is Polish it will render the verify_email_pl.scala.html otherwise if your browser uses language not supported by PA, it will silently fallback to: verify_email_en.scala.html. Check the usage and declaration of the method. For your case it will be good solution, of course just criteria of the choice will be different.

Categories : Java

Play framework SOLID principles
You are right, the majority of samples does not use Dependency Injection. But since the 2.1 version, it is possible to inject the controllers, and their dependencies. For the dependency injection, check the doc and also, how to unit test (last paragraph). But since there are many static calls, you could end up with some static reference somewhere and you'll not be able to unit test your code. But I think Play is a great framework, the team is modularizing more and more the framework, so that it will be better and better regarding SOLID principles.

Categories : Scala

Play Framework 2.1.1 deployment on Heroku
You are using an MySQL syntax. Could you post your SQL? I suspect you use INTEGER NOT NULL AUTO_INCREMENT While you should use SERIAL PRIMARY KEY

Categories : Postgresql

Play Framework 2 view declaration
In first line you need to declare parameters of the view (which is a Scala function as you know from the doc) however if view doesn't get any params most probably you can remove the @() line without any problem.

Categories : Scala

How to show images in play framework 2.1
The code that you are using is for Playframework 1.x, and it is not compatible with the 2.x version. These two versions are totally different. As @rags mentioned, take a look at How to render a binary with play 2.0? More explanations on Content-Type are available here: http://www.playframework.com/documentation/2.1.1/JavaResponse

Categories : Java

Play Framework 1.2.5 Hibernate upgrade to v 4.2.4
I guess hibernate 3.x and 4.x are not fully compatible so you have to modify some source code of the framework itself to use this version of hibernate. You can start from the 1.3.x github branch that is shipped with hibernate 4.1.3 : https://github.com/playframework/play1/tree/1.3.x

Categories : Java

How to work with ajax in play framework 2.1.*
Few weeks ago I implemented uploading files with ajax with usage of jquery-file-upload. I might post my solution and I hope you will be satisfied. This example is for simple 1 file upload but it can be extended. Scripts <script src="@routes.Assets.at("javascripts/jquery-file-upload/jquery.iframe-transport.js")" type="text/javascript"></script> <script src="@routes.Assets.at("javascripts/jquery-file-upload/vendor/jquery.ui.widget.js")" type="text/javascript"></script> <script src="@routes.Assets.at("javascripts/jquery-file-upload/jquery.fileupload.js")" type="text/javascript"></script> View <input type="file" id="@d" name="@d" data-url="@code.routes.Ext.upload()" /> <script type="text/javascript"> $(document).ready(function () {

Categories : Java

How to get form data in Play Framework
The POST data is available in a controller with request().body(). On the body, you can call .asFormUrlEncoded() to retrieve a Map of the data. You will find more information in the documentation. For more complex use cases, you can use the Form API to define data constraints and validation and bind data directly to a specific class.

Categories : Java

Jasmine, require and play framework
The guardian one is deprecated. The new repo is at https://github.com/joescii/sbt-jasmine-plugin Have you tried that one? Edit: I've also built my own plugin for this purpose: https://github.com/tanin47/sbt-web-test-js The differences from sbt-jasmine-plugin are: The testers can be in Coffeescripts It uses PhantomJS to execute the test HTML files. sbt-jasmine-plugin uses env-js + Rhino, which, in my opinion, is less robust.

Categories : Javascript

Play framework can't find javac
Make sure that the javac is in the OS's search path For example, on Windows, goto Control Panel -> System, click Advanced System Settings, click on Environment Variables. In the System variables, locate the variable named path and insert C:Program FilesJavajdk1.7.0_25in at the start of the value. Don't forget to add ; between the values ;) Click Okay, Okay. Close any command prompt windows you have open and re-open them. This will ensure that they are updated with the new environment variables.

Categories : Java

Best mongodb driver for Play Framework 2.1
I didn't do any comparison so I wouldn't claim it's the best, but when I started with my current project there was only salat with its Play! plugin. It's quite well documented (see its github wiki) and under active development. I'd say it has production quality. If the documentation isn't enough for you there are samples of usage in the test suites in the repository.

Categories : Mongodb

Multiple Databases with Play Framework 2.1.x
Ok, your application.conf seems to be correct. You may use the secondary server like this: EbeanServer secondary = Ebean.getServer("secondary"); secondary.find(User.class).findList(); Once you've got your secondary server, you may treat it just as you treat the Ebean singleton.

Categories : Java

List of pair in Play Framework
Your fields value is of type java.util.ArrayList, but the parameter expected by index.scala.html is a scala.collection.immutable.List - hence the type mismatch.

Categories : Scala

Scala Play Framework 2.1.1 JSON
__ is an alias for JsPath companion object is the operator to parse the symbol to read from the Json object. And tupled just puts them into a tuple so you can do something like case (name, age) => as in the example in the doc you posted.

Categories : Json

Play Framework Error on BindRequest
Your User class is required to have a default constructor. By providing a constructor with no formal paramaters, you have overridden the default constructor, therefore one is not being generated at compile time. Try removing the constructor and see if it fixes the problem.

Categories : Java

Can not access parameters in play framework
You need to edit to: GET /image/:filter1/:pageno1 controllers.Application.pagination(filter1: String, pageno1: Int) This is because though you have mentioned the generator, but you haven't explicitly mentioned the regex for what is filter1 and pageno1. Just doing GET /image means you are passing a parameter image to the call Get /:st whatever(st: String) Correcting it should solve the Issue You can also use Parameters with default values like this: GET /image controllers.Application.pagination(filter1: String ?= "", pageno1: Int ?= 0)

Categories : Scala

Displaying PDF with Java Play! 2 framework
Just send the binary representation, and specify the PDF content type: public static Result createPDF() { byte[] pdfAsBinary = ... response().setContentType("application/pdf"); return ok(pdfAsBinary); }

Categories : Pdf

Can't get the id in play framework scala program
The error message tells you what is wrong. Your userprofiles is a list of UserProfile. It does not have a member called id. Yet, you are trying to access it: @for(userprofile <- userprofiles.id) // ^--- this is invalid I think what you are trying to do is: @for(up <- userprofiles){ @if(up.id == userprofile.id) {} else { ... } }

Categories : Scala

Play framework if else case Not working
You have shadowing issues in your code: userprofile is both defined as a parameter of your template and as the variable you get out of the for comprehension. @(userprofiles: List[UserProfile],myFriend:models.MyFriend,userprofile:models.UserProfile,useraccount:models.UserAccount) here ---^ @helper.form(action = routes.Application.createMyFriend) { <br/><br/><br/> @for(userprofile <- userprofiles){ and here ---^ Try renaming one of the two and sort out which one you want to refer to in your if.

Categories : Scala

Play Framework (2.1.3) doesn't run any tests
It's a known issue of Play 2.1.3. Meanwhile there is a workaround. Add the following into Build.scala file in the val main function: val main = play.Project(appName, appVersion, appDependencies).settings( // Add your own project settings here testOptions in Test ~= { args => for { arg <- args val ta: Tests.Argument = arg.asInstanceOf[Tests.Argument] val newArg = if(ta.framework == Some(TestFrameworks.JUnit)) ta.copy(args = List.empty[String]) else ta } yield newArg } )

Categories : Java

Deploying play framework on weblogic
In play1.x, we can package the project to a war, by using play warhowever Play 2.x doesn't allow that. You could use external plugins https://github.com/dlecan/play2-war-plugin to package your apps into standard WAR packages from Play framework 2.

Categories : Java

Play Framework form with history
I would normalize and persist the record in the database. This would allow you to have history on changes by having a history table for each section that they with to rollback. This would allow manageability of restorations based on sets of data and significant changes can be tracked. Managing each field separately would be very cumbersome and least pragmatic.

Categories : Forms



© Copyright 2017 w3hello.com Publishing Limited. All rights reserved.