Announcement Announcement Module
Collapse
No announcement yet.
Update/Edit from list views Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Update/Edit from list views

    Hi,

    I'd like to have an edit button in front of each row of my list.
    Even after googling a lot I can't find out to properly do it.

    I am trying the following starting from the generated method but cannot find how to handle the version number (e.g. locking).

    List view:
    Code:
    <g:each in="${internalNoteInstanceList}" var="item">
    		<tr>
    			<td>
    				<a href="${createLink(controller:'internalNote',action:'update',id:''+item.id)}">
    					<g:img dir="images" file="edit.png" />
    				</a>
    			</td>
    Controller:
    Code:
        def update(Long id, Long version) {
            def internalNoteInstance = InternalNote.get(id)
            if (!internalNoteInstance) {
                flash.message = message(code: 'default.not.found.message', args: [message(code: 'internalNote.label', default: 'InternalNote'), id])
                redirect(action: "list")
                return
            }
    
            if (version != null) {
                if (internalNoteInstance.version > version) {
                    internalNoteInstance.errors.rejectValue("version", "default.optimistic.locking.failure",
                              [message(code: 'internalNote.label', default: 'InternalNote')] as Object[],
                              "Another user has updated this InternalNote while you were editing")
                    render(view: "edit", model: [internalNoteInstance: internalNoteInstance])
                    return
                }
            }
    
            internalNoteInstance.properties = params
    
            if (!internalNoteInstance.save(flush: true)) {
                render(view: "create", model: [internalNoteInstance: internalNoteInstance])
                return
            }
    
            flash.message = message(code: 'default.updated.message', args: [message(code: 'internalNote.label', default: 'InternalNote'), internalNoteInstance.id])
            redirect(action: "show", id: internalNoteInstance.id)
        }

  • #2
    Hi,

    Try something like this, you should be able to access it by item.version:

    Code:
    def update = {
        def internalNoteInstance = InternalNote.get(params.id)
    Then in your view you pass them like this:
    Code:
        <g:createLink controller="internalNote" action="update" params="[id: '${item.id}', version: '${item.version}]"/>

    Comment

    Working...
    X