Grails:如何消除 create.gsp 和 save.gsp 并将其移动到 list.gsp 中列表的第一行?
我想摆脱 create.gsp 和 save.gsp 并将所有内容都放在同一页面上。 我所做的是将所有这些字段移至 list.gsp 中列表的第一行,
但现在我不知道如何将其与其余数据连接并使其工作。
我必须让创建按钮起作用。但随后我无法使更新按钮工作。
这是第一行的图片
所有内容都在第一行中创建,然后单击“创建”,将创建一个新行,其中所有数据都放入文本字段中。第一行没有 ID,但其他行都有。
我还让擦除按钮起作用了。所以基本上唯一缺少的是更新按钮。
有什么想法吗?
提前致谢!
编辑
这是我在控制器中的内容:
def update = {
def densityInstance = Density.get(params.id)
if (densityInstance) {
if (params.version) {
def version = params.version.toLong()
if (densityInstance.version > version) {
densityInstance.errors.rejectValue("version", "default.optimistic.locking.failure", [message(code: 'density.label', default: 'Density')] as Object[], "Another user has updated this Density while you were editing")
render(view: "list", model: [densityInstance: densityInstance,'Rcommodity':params?.Rcommodity])
}
}
densityInstance.properties = params
if (!densityInstance.hasErrors() && densityInstance.save(flush: true)) {
flash.message = "${message(code: 'default.updated.message', args: [message(code: 'density.label', default: 'Density'), densityInstance.id])}"
redirect(action: "list", id: densityInstance.id)
}
else {
redirect(action: "list", id: densityInstance.id)
}
}
else {
flash.message = "${message(code: 'default.not.found.message', args: [message(code: 'density.label', default: 'Density'), params.id])}"
redirect(action: "list")
}
}
由于grails按列进行操作,因此行有点混乱,但它是:
<g:each in="${densityInstanceList}" status="i" var="densityInstance">
<g:form action="update">
<tr class="${(i % 2) == 0 ? 'even' : 'odd'}">
<td>${fieldValue(bean: densityInstance, field: "id")}</td>
<td><g:textField name="Rcommodity" value="${densityInstance?.commodity}" class="input" onKeyPress="return alpha(event)"/> <img src="${resource(dir:'images/skin',file:'information.png')}" ></td>
<td><g:textField name="Rorigin" value="${densityInstance?.origin}" maxlength="3" size="5" class="input" onKeyPress="return alpha(event)"/> <img src="${resource(dir:'images/skin',file:'information.png')}" ></td>
<td><g:textField name="Rshipper" value="${densityInstance?.shipper}" size="3" class="input" onkeypress="return IsNumeric(event)"/> <g:textField name="RshipperName" value="${densityInstance?.shipperName}" size="15" class="input-b" onfocus="this.blur()"/> <img src="${resource(dir:'images/skin',file:'information.png')}" ></td>
<td><g:textField name="Ragent" value="${densityInstance?.agent}" size="3" class="input" onkeypress="return IsNumeric(event)"/> <g:textField name="RagentName" value="${densityInstance?.agentName}" size="15" class="input-b" onfocus="this.blur()"/> <img src="${resource(dir:'images/skin',file:'information.png')}" ></td>
<td><g:textField name="Rdest" value="${densityInstance?.dest}" size="5" class="input" onKeyPress="return alpha(event)"/> <img src="${resource(dir:'images/skin',file:'information.png')}" ></td>
<td><g:textField name="Rdensity" value="${densityInstance?.density}" size="15" class="input" onkeypress="return IsNumeric(event)"/></td>
<td><g:textField name="RAM" value="${densityInstance?.AM}" size="1" class="input"/></td>
<td width="100">
<g:form>
<g:hiddenField name="id" value="${densityInstance?.id}" />
<g:actionSubmit class="editar" action="update" value="${message(code: 'default.button.editar.label', default: ' ')}" />
<g:actionSubmit class="eliminar" action="delete" value="${message(code: 'default.button.eliminar.label', default: ' ')}" onclick="return confirm('${message(code: 'default.button.delete.confirm.message', default: 'Esta seguro que desea Eliminar?')}');" />
</g:form>
</td>
</tr>
</g:form></g:each>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
为了摆脱 create.gsp 和 edit.gsp,控制器的操作应该与脚手架中的操作完全相同,除了 save{} 和 update{} 应该以
In order for "Update" Buttons to work, every "Update" 结尾应将其表单(表格的一行)提交给“更新”操作。有关 update{} 的其他所有内容均应保持原样。
当然,该线条形式应该包含所有对象属性。
代码示例后更新。
params
是否包含对象字段。In order to get rid of create.gsp and edit.gsp, your controller's actions should work exactly like in scaffolding, except for save{} and update{} should end with
In order for "Update" buttons to work, every "Update" should submit its form (one line of the table) to "update" action. Everything else about update{} should remain as it was.
That line form should contain all the object properties, for sure.
UPDATE after code sample.
params
contain object fields.我认为问题在于您的 actionSubmits 正在提交包含它们的表单,并且您的数据元素位于外部表单中,因此您的更新操作调用不会收到任何要更新的数据。如果您在更新操作的顶部放置一些调试,您可以证明或反驳这个理论。
println“${params}”
I believe the issue is that your actionSubmits are submitting the form containing them and your data elements are in the outer form so your update action call is not receiving any data to be updated. If you put some debug in the top of the update action, you could prove or disprove this theory.
println "${params}"