source: trunk/grails-app/controllers/InventoryLocationDetailedController.groovy @ 230

Last change on this file since 230 was 178, checked in by gav, 15 years ago

Resolve ticket #12 again.
Turn query cache on again since this did not resolve the problem.
Implement fix as per http://jira.codehaus.org/browse/GRAILS-5111, add flush:true to save.
Adjust templates to include above and remove home url.
Re-generate all non detailed views and controllers.
Manually add flush:true and remove home url to detailed views and controllers.

File size: 3.9 KB
RevLine 
[125]1import org.codehaus.groovy.grails.plugins.springsecurity.Secured
2
[175]3class InventoryLocationDetailedController extends BaseController {
[125]4   
5    def index = { redirect(action:list,params:params) }
6
7    // the delete, save and update actions only accept POST requests
8    static allowedMethods = [delete:'POST', save:'POST', update:'POST']
9
10    def list = {
11        params.max = Math.min( params.max ? params.max.toInteger() : 10,  100)
[175]12        [ inventoryLocationInstanceList: InventoryLocation.list( params ), inventoryLocationInstanceTotal: InventoryLocation.count() ]
[125]13    }
14
15    def show = {
[175]16        def inventoryLocationInstance = InventoryLocation.get( params.id )
[125]17
[175]18        if(!inventoryLocationInstance) {
19            flash.message = "InventoryLocation not found with id ${params.id}"
[125]20            redirect(action:list)
21        }
[175]22        else { return [ inventoryLocationInstance : inventoryLocationInstance ] }
[125]23    }
24
25    def delete = {
[175]26        def inventoryLocationInstance = InventoryLocation.get( params.id )
27        if(inventoryLocationInstance) {
[125]28            try {
[175]29                inventoryLocationInstance.delete(flush:true)
30                flash.message = "InventoryLocation ${params.id} deleted"
[125]31                redirect(action:list)
32            }
33            catch(org.springframework.dao.DataIntegrityViolationException e) {
[175]34                flash.message = "InventoryLocation ${params.id} could not be deleted"
[125]35                redirect(action:show,id:params.id)
36            }
37        }
38        else {
[175]39            flash.message = "InventoryLocation not found with id ${params.id}"
[125]40            redirect(action:list)
41        }
42    }
43
44    def edit = {
[175]45        def inventoryLocationInstance = InventoryLocation.get( params.id )
[125]46
[175]47        if(!inventoryLocationInstance) {
48            flash.message = "InventoryLocation not found with id ${params.id}"
[125]49            redirect(action:list)
50        }
51        else {
[175]52            return [ inventoryLocationInstance : inventoryLocationInstance ]
[125]53        }
54    }
55
56    def update = {
[175]57        def inventoryLocationInstance = InventoryLocation.get( params.id )
58        if(inventoryLocationInstance) {
[125]59            if(params.version) {
60                def version = params.version.toLong()
[175]61                if(inventoryLocationInstance.version > version) {
[125]62                   
[175]63                    inventoryLocationInstance.errors.rejectValue("version", "inventoryLocation.optimistic.locking.failure", "Another user has updated this InventoryLocation while you were editing.")
64                    render(view:'edit',model:[inventoryLocationInstance:inventoryLocationInstance])
[125]65                    return
66                }
67            }
[175]68            inventoryLocationInstance.properties = params
[178]69            if(!inventoryLocationInstance.hasErrors() && inventoryLocationInstance.save(flush: true)) {
[175]70                flash.message = "InventoryLocation ${params.id} updated"
71                redirect(action:show,id:inventoryLocationInstance.id)
[125]72            }
73            else {
[175]74                render(view:'edit',model:[inventoryLocationInstance:inventoryLocationInstance])
[125]75            }
76        }
77        else {
[175]78            flash.message = "InventoryLocation not found with id ${params.id}"
79            redirect(action:list)
[125]80        }
81    }
82
83    def create = {
[175]84        def inventoryLocationInstance = new InventoryLocation()
85        inventoryLocationInstance.properties = params
86        return ['inventoryLocationInstance':inventoryLocationInstance]
[125]87    }
88
89    def save = {
[175]90        def inventoryLocationInstance = new InventoryLocation(params)
[178]91        if(!inventoryLocationInstance.hasErrors() && inventoryLocationInstance.save(flush: true)) {
[175]92            flash.message = "InventoryLocation ${inventoryLocationInstance.id} created"
93            redirect(action:show,id:inventoryLocationInstance.id)
[125]94        }
95        else {
[175]96            render(view:'create',model:[inventoryLocationInstance:inventoryLocationInstance])
[125]97        }
98    }
99}
Note: See TracBrowser for help on using the repository browser.