[英]Grails: How do I eliminate the create.gsp and save.gsp and move it to the first line of the list in list.gsp?
I want to get rid of the create.gsp and save.gsp and have everything on the same page. 我想摆脱create.gsp和save.gsp,并将所有内容都放在同一页面上。 What I did is move all those fields into the first row of my list in list.gsp
我所做的就是将所有这些字段移到list.gsp列表的第一行中
But now I don't know how to connect it with the rest of the data and make it work. 但是现在我不知道如何将其与其余数据连接起来并使其正常工作。
I got to make the create button work. 我必须使创建按钮起作用。 But then I cannot make the update button work.
但是,然后我无法使更新按钮起作用。
Here is a picture of how the first rows look like 这是第一行的样子
Everything is created in the first row then you click CREATE and a new row gets created with all the data put in the textfields. 一切都在第一行中创建,然后单击CREATE,然后创建一个新行,并将所有数据放入文本字段中。 The first row does not have an ID, but all of the others do.
第一行没有ID,但其他所有行都有ID。
I also got the erase button to work. 我还可以使用“擦除”按钮。 So basically the only thing missing is the UPDATE button.
因此,基本上唯一缺少的是UPDATE按钮。
Any ideas?? 有任何想法吗??
Thanks in advance! 提前致谢!
EDIT 编辑
Here is what I have in the controller: 这是我在控制器中拥有的:
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")
}
}
And since grails does it by columns the row is kinda messy but here it is: 而且由于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>
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 为了摆脱create.gsp和edit.gsp,控制器的动作应与脚手架中的动作完全相同,但save {}和update {}的结尾应为
redirect(action: list)
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.
关于update {}的其他所有内容均应保持原样。
That line form should contain all the object properties, for sure. 当然,该线形应包含所有对象属性。
UPDATE after code sample. 代码示例后更新 。
params
contain object fields. 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. 我认为问题在于您的actionSubmits正在提交包含它们的表单,并且您的数据元素位于外部表单中,因此您的update action调用未收到任何要更新的数据。 If you put some debug in the top of the update action, you could prove or disprove this theory.
如果在更新操作的顶部放置一些调试,则可以证明或反驳这一理论。
println "${params}"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.