2
votes

I want to pass the name of a field as a parameter to a custom Play! framework tag:

  #{ifError ${_field}}
    <ul class="err">
    #{errors ${_field}}
      <li>${error}</li>
    #{/errors}
    </ul>
  #{/ifError}

But all I get is the exception:

Template execution error (In /app/views/tags/errorList.html around line 1)
Execution error occured in template /app/views/tags/errorList.html. Exception raised was MissingMethodException : No signature of method: Template_1008.$() is applicable for argument types: (Template_1008$_run_closure1_closure2) values: [Template_1008$_run_closure1_closure2@2da75e1b] Possible solutions: _(java.lang.String), is(java.lang.Object), run(), run(), any(), get(java.lang.String).

play.exceptions.TemplateExecutionException: No signature of method: Template_1008.$() is applicable for argument types: (Template_1008$_run_closure1_closure2) values: [Template_1008$_run_closure1_closure2@2da75e1b]

How can I pass the parameter to my tag?

Solution

I have slightly modified the solution of "Codemwnci" and ended up with the following template code:

#{ifError _arg}
  <ul class="err">
  #{errors _arg}
    <li>${error}</li>
  #{/errors}
  </ul>
#{/ifError}

This template is called like this #{errorList 'document.title' /}

1

1 Answers

2
votes

Because you are already inside a piece of Groovy code by using the tag syntax #{..}, you do not need to use the Expression syntax (i.e. you don't need to use the ${..} syntax).

Also, the errors tag does not take any input, you instead need to pass the field name into the error tag. You can check this documentation for details of the error tag.

The following should work for you

#{ifError _field}
  <ul class="err">
    <li>#{error _field /}</li>
  </ul>
#{/ifError}