gpt4 book ai didi

java - Play Framework : passing parameter to custom tag

转载 作者:行者123 更新时间:2023-11-30 09:44:33 26 4
gpt4 key购买 nike

我想将字段名称作为参数传递给 custom Play! framework tag :

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

但我得到的只是异常(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]

如何将参数传递给我的代码?

解决方案

我稍微修改了“Codemwnci”的解决方案,最后得到以下模板代码:

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

这个模板是这样调用的 #{errorList 'document.title'/>

最佳答案

因为您已经通过使用标记语法 #{..} 进入了一段 Groovy 代码,所以您不需要使用表达式语法(即您不需要使用${..} 语法)。

此外,errors 标签不接收任何输入,您需要将字段名称传递给错误标签。你可以查看this documentation error 标签的详细信息。

以下应该对你有用

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

关于java - Play Framework : passing parameter to custom tag,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7859908/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com