我需要发送一个参数到文件renderEditor.template(在安装“grails install-templates”之后),但我不知道如何。谁能帮我?谢谢。GRAILS:将参数发送到renderEditor.template
回答
可供renderEditor.template
的绑定变量固定在DefaultGrailsTemplateGenerator
def binding = [pluginManager: pluginManager,
property: property,
domainClass: domainClass,
cp: cp,
domainInstance:getPropertyName(domainClass)]
domainClass
作为GrailsDomainClass
,property
被传递给在脚手架模板renderEditor(p)
呼叫GrailsDomainClassProperty
和cp
是相应ConstrainedProperty
。您可能能够从其中一个中提取您需要的内容。
好吧,如何通过这些对象知道renderEditor呈现哪个模板?我在两个不同的模板中有两种不同的情况,我必须以不同的方式处理。对不起英文 –
@PhillipParente我不认为你不幸。我可以看到修改'DefaultGrailsTemplateGenerator'使其可以将任意参数传递给'renderEditor.template'并不难,但是我没有办法在没有这样的代码改变的情况下实现它。 –
好的,是最好的方法。谢谢 –
对于谁得到这里通过谷歌有同样问题的其他人(像我一样)
我已经成功在伊恩·罗伯茨提出类似的方式这样做,但你并不需要创建新的实现为模板生成器。所有你需要的是创造代理执行org.codehaus.groovy.grails.commons.GrailsDomainClassProperty
_form.gsp里面我也刚刚创建的新属性添加了数据:
p = new HgfGrailsDomainClassProperty(p, prefix, domainClass)
if (display) { %>
<hgf:ifAllowedOnField action="show" field="${p.name}">
<hgf:ifReasonToShow reasonElement="${p.name}" bean="\${${propertyName}}">
<div class="fieldcontain \${hasErrors(bean: ${propertyName}, field: '${prefix}${p.name}', 'error')} ${required ? 'required' : ''} ${(cp?.metaConstraints?.hiddenField)?'hiddenProperty':''}">
<label for="${prefix}${p.name}">
<g:message code="${domainClass.propertyName}.${prefix}${p.name}.label" default="${p.naturalName}" />
<% if (required) { %><span class="required-indicator">*</span><% } %>
</label>
${renderEditor(p)}
...
实施可以是这个样子:
package sk.hoppo.hgf;
import org.codehaus.groovy.grails.commons.GrailsDomainClass
import org.codehaus.groovy.grails.commons.GrailsDomainClassProperty
public class HgfGrailsDomainClassProperty implements GrailsDomainClassProperty {
private final String domainSuffix = "Instance";
private GrailsDomainClassProperty property;
String prefix;
String domainInstance;
public HgfGrailsDomainClassProperty(GrailsDomainClassProperty property, String prefix, GrailsDomainClass parentDomainClass) {
super();
this.property = property;
this.prefix = prefix;
domainInstance = getPropertyName(parentDomainClass);
}
private String getPropertyName(GrailsDomainClass domainClass) {
return "${domainClass.propertyName}${domainSuffix}";
}
@Override
public int getFetchMode() {
return property.getFetchMode();
}
@Override
public String getName() {
return property.getName();
}
...
的renderEditor.template里你刚刚访问发送数据:
sb << '<hgf:securedField'
sb << ' name="' << property.prefix << property.name << '"'
sb << ' field="' << property.prefix << property.name << '"'
顺便说一句。与此我已经使作品(嵌入)与我的自定义渲染编辑器正常工作
- 1. 将参数发送到ftw()
- 2. 将参数发送到其他站点
- 3. 将参数从java发送到jsp
- 4. 将参数发送到命令行
- 5. 将参数发送到存储过程
- 6. ModalPopupExtender将参数发送到PopupControl?
- 7. 将多个参数发送到cmd C#
- 8. 将参数发送到远程网站
- 9. SignalR - 将参数发送到OnConnected?
- 10. 将空参数发送到PHP的JavaScript
- 11. 使用node.js将参数发送到API
- 12. swift 3将json参数发送到api
- 13. 发送参数到webservice
- 14. 发送参数到URL
- 15. 发送参数到before_save
- 16. 发送typoscript参数到userFunc
- 17. 如何将参数输出发送到另一个参数
- 18. Grails - 将参数添加到params地图
- 19. 发送参数
- 20. 发送参数
- 21. 当连接android到php有时参数不发送时,发送参数到php
- 22. 将参数从JSP发送到PHP使用JSP:转发
- 23. Grails发送错误
- 24. Mule:如何将数组参数发送到数据库更新
- 25. 将参数发送到HTML函数的javascript函数
- 26. 发送参数到jQuery函数
- 27. 发送SQL查询参数到函数
- 28. 发送参数到jQuery函数
- 29. Objective-C发送参数到void函数
- 30. 发送多个参数到WinJS.Binding.converter()函数
你能说明你正在尝试做什么吗? renderEditor.template仅用于在呈现HTML表单时将表单字段转换为调用该文件中的私有方法。如何或者你想要做什么,需要传递一个参数。试图了解目标...... –
我知道,但我需要通过_form.gsp“renderEditor(p)”中的调用发送参数,例如renderEditor(p,“myString”)以在renderEditor中进行操作。模板。击倒英语 –