如果ID在show.gsp中有不同的名称以使删除工作,如何修改g:form标签?

时间:2014-12-27 17:15:27

标签: grails gorm

我的域类ID已映射到bookId

class Book {
    int id
    int bookId
    String bookAuthor

    static constraints = {
        bookAuthor blank: false, maxSize:30         
    }

    static mapping = {    
        version false
        id generator: 'sequence',
        params: [sequence:'s_book_seq'],
        name: 'bookId'
    }
}

这导致生成的show.gsp无法理解用于编辑和删除的ID。我能够修改编辑链接,使其识别bookId。但不确定如何修改删除按钮代码。请指教。

<g:form url="[resource:bookInstance, action:'delete']" method="DELETE">
    <fieldset class="buttons">
        <g:link class="edit" action="edit" id="${bookInstance.bookId}" ><g:message code="default.button.edit.label" default="Edit" /></g:link></td>
        <g:actionSubmit class="delete" action="delete"  value="${message(code: 'default.button.delete.label', default: 'Delete')}" onclick="return confirm('${message(code: 'default.button.delete.confirm.message', default: 'Are you sure?')}');" />
    </fieldset>
</g:form>

1 个答案:

答案 0 :(得分:1)

您需要添加隐藏字段,以便在提交表单时发送id参数,例如

<g:form url="[resource:bookInstance, action:'delete']" method="DELETE">

    <g:hiddenField name="id" value="${bookInstance.bookId}" />

    <fieldset class="buttons">
        <g:link class="edit" action="edit" id="${bookInstance.bookId}" ><g:message code="default.button.edit.label" default="Edit" /></g:link></td>
        <g:actionSubmit class="delete" action="delete"  value="${message(code: 'default.button.delete.label', default: 'Delete')}" onclick="return confirm('${message(code: 'default.button.delete.confirm.message', default: 'Are you sure?')}');" />
    </fieldset>
</g:form>