scala-template

Scala: abstract type pattern A is unchecked since it is eliminated by erasure

耗尽温柔 提交于 2021-02-08 12:16:35
问题 I am writing the function that can catch exceptions of the certain type only. def myFunc[A <: Exception]() { try { println("Hello world") // or something else } catch { case a: A => // warning: abstract type pattern A is unchecked since it is eliminated by erasure } } What is the corrent way to bypass jvm type erasure in such case? 回答1: You could use ClassTag like in this answer. But I'd prefer this approach: def myFunc(recover: PartialFunction[Throwable, Unit]): Unit = { try { println("Hello

Scala Play framework: Binding form parameters to hidden fields

烂漫一生 提交于 2019-12-21 12:02:24
问题 I am working with Play 2.0.4 and have the following form in my scala template. @fieldGroup(field: Field, className: String = "field") = { <div class="twipsies well @className"> <a class="removeField btn danger pull-right">Remove Field</a> @inputText( // <=== I need a hidden input field here field("id") ) @inputText( field("name"), '_label -> "Name", '_help -> "Use lower case, starts with an alphabet can contain numbers and underscores." ) } I need a few hidden fields in my forms, how do I

Scala Play framework: Binding form parameters to hidden fields

时间秒杀一切 提交于 2019-12-21 12:02:23
问题 I am working with Play 2.0.4 and have the following form in my scala template. @fieldGroup(field: Field, className: String = "field") = { <div class="twipsies well @className"> <a class="removeField btn danger pull-right">Remove Field</a> @inputText( // <=== I need a hidden input field here field("id") ) @inputText( field("name"), '_label -> "Name", '_help -> "Use lower case, starts with an alphabet can contain numbers and underscores." ) } I need a few hidden fields in my forms, how do I

How to use scala and html code inside single block

◇◆丶佛笑我妖孽 提交于 2019-12-12 01:35:22
问题 why option html element is not binded inside select in case 1? Case 1: not work @base{ <select name="" value="" class="custom-select"> @{ println("1"); // this is printed to console <option value="test">i</option> // this is not shown in html println("2"); // this is printed to console } </select> } Case 2: work @base{ <select name="" value="" class="custom-select"> @{ println("1"); // this is printed to console <option value="test">i</option> // this is shown in html } </select> } Update:

Scala Template apply style to inputText's label [Play 2 HTML5 helper tag]

喜欢而已 提交于 2019-12-07 17:25:08
问题 I am using scala template with input helper. The class attribute which i use applies style for the <input> tag. How do i apply the style specific to the generated <label> tag? @inputText(orderItem("item1"),'_label -> "Product*",'_class -> "tinytfss") Thanks in advance for your support. Manoj 回答1: You could try ditching the built-in field constructors and instead write your own. The following template accepts a custom argument that controls the styling of the label: app/views/_my_field

Scala Template apply style to inputText's label [Play 2 HTML5 helper tag]

戏子无情 提交于 2019-12-06 01:20:05
I am using scala template with input helper. The class attribute which i use applies style for the <input> tag. How do i apply the style specific to the generated <label> tag? @inputText(orderItem("item1"),'_label -> "Product*",'_class -> "tinytfss") Thanks in advance for your support. Manoj You could try ditching the built-in field constructors and instead write your own . The following template accepts a custom argument that controls the styling of the label: app/views/_my_field_constructor.scala.html @(element: helper.FieldElements) <div class="clearfix @if(element.hasErrors){error}">

How to convert scala list to javascript array?

房东的猫 提交于 2019-12-05 21:13:59
问题 Is there a simpler way of doing this? $(document).ready(function () { var jsArray = [] @if(scalaList != null) { @for(id <- scalaList) { jsArray.push('@id'); } } ... } 回答1: It's as simple as the following: import play.api.libs.json.Json val jsArr: JsValue = Json.toJson(scalaList) You can also do that within a template: @(list: List[Any]) @import play.api.libs.json.Json <script type="text/javascript"> $(document).ready(function () { var jsArr = @Json.toJson(list); console.log(jsArr); }); <

How to prefill a dropdown using scala template and play framework

♀尐吖头ヾ 提交于 2019-12-05 07:42:01
问题 I am using scala template and Play 2.0 framework for my project. Let's say I have a user form with fields like name (textfield), age (dropdown). While creating the user I filled name as dave and selected age as 25. Now on my edit screen, I want my values to be prefilled, i know how to do it with textfield (i.e. set value as userForm('name')) but what about the dropdown? how to do it. 回答1: Thanks Shawn Downs and biesior. Well, we can use @select scala helper class to show the pre-filled result

How to print @ symbol in HTML with play framework (scala)

*爱你&永不变心* 提交于 2019-12-04 20:10:18
问题 I am new to Scala and play 2.1 and I come from a PHP background. I am not able to print the @ symbol in HTML. I am getting the following error: not found: value Hotmail Here is my code: myname<label>@Hotmail.com</label> Please let me know how I can print the @ symbol. Thanks in advance. 回答1: Double it: myname<label>@@Hotmail.com</label> It's called escape syntax. Other rules for play template framework can be found here 回答2: You can also write HTML Entity code &#64 for printing @ symbol in

Scala Play framework: Binding form parameters to hidden fields

自作多情 提交于 2019-12-04 04:21:47
I am working with Play 2.0.4 and have the following form in my scala template. @fieldGroup(field: Field, className: String = "field") = { <div class="twipsies well @className"> <a class="removeField btn danger pull-right">Remove Field</a> @inputText( // <=== I need a hidden input field here field("id") ) @inputText( field("name"), '_label -> "Name", '_help -> "Use lower case, starts with an alphabet can contain numbers and underscores." ) } I need a few hidden fields in my forms, how do I bind it to the server side Form component? I have seen a @inputHidden template helper in the github