w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
While Sending Html Mails from my web application Recieved Mails contains Symbols like &ldquo,&rdquo, ‘
Check with another constructor for htmlView: ContentType mimeType = new System.Net.Mime.ContentType("text/html"); var htmlView = AlternateView.CreateAlternateViewFromString(bodyMessage, mimeType);

Categories : Asp Net Mvc

Play framework scala template with case statement on enumeration
You don't have to use try here, just the wild card in you match (see: http://www.playframework.com/documentation/2.1.x/ScalaTemplateUseCases). @(tagStatus: String) @tagStatus match { case TagStatus.deployed.toString => {<span class="label label-success">@tagStatus</span>} case TagStatus.deployedPartially.toString => {<span class="label label-important">@tagStatus</span>} case TagStatus.deployedWithProblems.toString => {<span class="label label-important">@tagStatus</span>} case _ => {<span class="label label-important">??</span>} }

Categories : Scala

How to return model query result as JSON in scala play framework
I recommend you use play.api.libs.Json.toJson. Here's an example: object Products extends Controller { def list = Action { val productCodes = Product.findAll.map(_.ean) Ok(Json.toJson(productCodes)) } Json.toJson returns a JsValue for which Play will automatically add a application/json header. See Play For Scala chapter 8.

Categories : Scala

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

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

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

Scala Play framework 2.1 derived classes
The json API extensively uses implicit parameters which is a feature of Scala where you can provide an "implicit" parameter list and if you don't specify those parameters the compiler will try to find an object in the current scope that is marked as implicit and matches that signature. So if you for example would write: implicit val s = "my implicit string" def magicPrint(implicit message: String) { println(message) } // and then call it magicPrint The compiler would select s for the parameter message since it is in scope and has the correct type (String), so after the implicit resolution the last line of code would actually look more like this magicPrint(s) The Format/Writer is selected by the compiler, at compile time, with an implicit parameter. If you look at the signature of

Categories : Scala

Play framework scala and mysql error
I think it would work if you removed the quotes altogether (or use backticks, as suggested by Carsten). Here is the doc: http://dev.mysql.com/doc/refman/5.0/en/identifiers.html

Categories : Mysql

Accessing value by javascript Play Framework/Scala
1) Is this code in your controller? And are the node variable in scope? If so this should be perfectly legal code, since it will be evaluated as pure scala. 2) The templates are a different story however. You probably know they parse everything as normal html, unless escaped. To use a variable you have to bring it into scope by either: defining a 'constructor' for the template at the absolute beginning of the file: @(node : Node) ... @node.name // later in the file See http://www.playframework.com/documentation/2.0/ScalaTemplates or define a variable inside the template: @defining( Get.node.from.somewhere ) { node => @node.name } See Play! framework: define a variable in template? If you did either of the two, you should have no problem accessing the node variable.

Categories : Scala

Run scala script with play framework classpath?
The easiest way is to do this from a play project and use the play console. create a new play project and go to the created folder launch the play console (just type play from your shell) from the play console, launch the scala console with the console command You can then load a specific scala file using :load. Ex : scala> :load /path/to/my_script.scala

Categories : Scala

Scala JavaScript Routing Play Framework
Your javascript route is defined as: GET /javascriptRoutes controllers.TrackController.javascriptRoutes Edit: play uses a special reverse route for javascript, under routes.javascript. so your reverse controller will be at controllers.routes.javascript.TrackController.Track: @helper.javascriptRouter("jsRoutes")( routes.javascript.TrackController.Track ) You also need to make an implicit RequestHeader available in your template. So add at the beginning of your template: @(implicit request: RequestHeader) Or if you already have template parameters: @(<your parameters>)(implicit request: RequestHeader) And make sure it is available in your controller's Action: def myController = Action { implicit request => // <-- request is a RequestHeader // ...

Categories : Scala

Play Framework Scala tuple in view
I know it might be one late answer, but I managed to solve this at that time. Code might be a bit dirty, but I hope it will come in handy to someone. Model part: def intersection(c1:Seq[String], c2:Seq[String]): Seq[String] = { (Set(c1: _*) & Set(c2: _*)).toSeq } Controller part: compareForm.bindFromRequest.fold( hasErrors = {errors => BadRequest(views.html.compares.index(compareForm, username, User.find(username)))}, success = { ldapName => val leftUser = Compare.findAll(ldapName._1) val rightUser = Compare.findAll(ldapName._2) val intersection = Compare.intersection(leftUser.memberOf,rightUser.memberOf) val rightLacking: Seq[String] = (leftUser.memberOf.toSet -- intersection.toSet).toList.map(_.toString).sorted val leftLacking: Seq[String] = (rightUse

Categories : Scala

How to define a default Action for any http method in Play 2.1 (Scala)?
You should not try to figure out all possible bad access points to generate error messages. Instead, you can override the onHandlerNotFound method in the application's Global object. Adapted from Play's official documentation: ScalaGlobal import play.api._ import play.api.mvc._ import play.api.mvc.Results.__ object Global extends GlobalSettings { override def onHandlerNotFound(request: RequestHeader): Result = { // implement methodNotAllowed controller Action } }

Categories : Http

How to trim a JsArray in Scala Play Framework 2.1 using transformers
It works, but probably it's not best option: import play.api.libs.json._ import play.api.libs.json.Reads._ import play.api.libs.functional.syntax._ val transformer: Reads[JsArray] = of[JsArray].map{ case JsArray(xs) => JsArray(xs.flatMap{ case x: JsObject => Some( x.transform( (__ "keyA").json.pickBranch and (__ "keyB").json.pickBranch reduce ).get ) }) }

Categories : Scala

How do I unit test a controller in play framework 2 scala
Using Mockito with Specs2, I mock services to verify their method calls. My controller is instantiated by Spring. That allows me to treat it is as a class instead of object. => That is essential to make controller testable. Here an example: @Controller class MyController @Autowired()(val myServices: MyServices) extends Controller To enable Spring for controllers, you have to define a Global object, as the Play! documentation explains: object Global extends GlobalSettings { val context = new ClassPathXmlApplicationContext("application-context.xml") override def getControllerInstance[A](controllerClass: Class[A]): A = { context.getBean(controllerClass) } } My unit test doesn't need Spring; I just pass collaborators (mocks) to constructor. However, concerning the render

Categories : Unit Testing

Understanding a Scala function from Play framework zentask example
A parameter of the form fn: => String represents a 'generator' (either a function or a value) that returns (or is) a String, so, for example, you might have a method defined as def myMethod(fn: => String): String = "Fn output = " + fn and call this as follows (the return types I use here can typically be inferred by the compiler, I'm just adding them for pedagogical purposes): def myFn: String = "Hello!" // Alternatively: def myFn(): String = "Hello!" // or: val myFn: () => String = "Hello!" // or most simply: val myString = "Hello!" val output = myMethod(myFn) // output = "Fn output = Hello!" Building on this, we can define a method that takes a function that turns a String into an Int, eg: def my2ndMethod(fn: String => Int): Int = fn("4") and call it as follows: de

Categories : Scala

Idea does not recognize plugins (on scala) for Play framework 2.1.1
You just need to relaunch the idea command, after sbt has refreshed your dependencies Add a dependency in Build.Scala sbt> reload sbt> idea Open idea, a popup will alert you to reload the project.

Categories : Intellij Idea

Using scala and java in play framework 2.1 : Session usage
I may be wrong, but I think that your Scala controllers should look like: def myaction() = Action { implicit request => ... } instead of: def myaction() = Action { ... } Ie, you have to add the request to the scope of your Action. And add it also to your view, at the beginning of the file: @(...)(implicit session:Session)

Categories : Java

scope and benefit of implicit parameter request in a scala play action?
1) Yes, the scope of the request is within the action block 2) Sorry, don't understand this question In general you should use implicits sparingly. We think the use of an implicit to pass around the request is reasonable in this particular context.

Categories : Scala

How to create a Java-based Play Framework Application (Not Scala)
It creates a SBT application on Cloudbees because any Play project is an SBT project. SBT is nothing more than a build system such as Maven (kind of) and SBT is in Scala (Scala Build Tool). No worries, you can code your whole Play application in Java without problem. Checkout the official documentation for more inforrmation.

Categories : Java

Add