Search code examples
scalaplayframeworkplayframework-2.4play-templates

'Missing parameter type' in Play template


I have the following template defined block in Play 2.4.6 (using scala 2.11.6 and sbt 0.13.8) abd I get a "mising parameter type" on the following code:

@property(budgetId: Int, propertyName: String, value: String, shouldEdit: Boolean = false, displayMethod: Option[String => String] = None) = {
  <div>
    <label class="prop-name">@displayMethod.getOrElse(String => propertyName)(propertyName)</label>
    @shouldEdit ? editable(budgetId, routes.Budgets.update(budgetId), "input", propertyName, value) : <span>@value</span>
  </div>
}

@editable(id: Int, url: Call, inputType: String, name: String, value:String) = {
    <div class="editable"
        data-editable-input="@inputType" data-editable-url="@url"
        data-editable-id="@id" data-editable-property="@name" >@value</div>
}

Anyone has any ideas of why that might be?


Solution

  • @displayMethod.getOrElse(String => propertyName) is the problem.

    String is actually an identifier here, and not the type String. So you have some function with a parameter name String, and the type of it is not known. The compiler will not infer the type to be String => String, because Option#getOrElse has a type parameter B >: A, which means it doesn't have to be String => String (just bounded below by it).

    You have to provide the type yourself. The clearest way would be to say:

    @displayMethod.getOrElse((_: String) => propertyName)
    

    Now we're declaring a function that is explicitly String => String, where the _ represents the single parameter that we don't care about.