@@ -40,17 +40,15 @@ class BookController {
4040
4141 def show (Long id ) {
4242 def bookInstance = Book . get(id)
43- if (! bookInstance) {
44- flash. message = message(code : ' default.not.found.message' , args : [message(code : ' book.label' , default : ' Book' ), id])
45- redirect(action : " list" )
46- return
47- }
48-
49- [bookInstance : bookInstance]
43+ bookInstanceRedirectIfItsNull(id, bookInstance)
5044 }
5145
5246 def edit (Long id ) {
5347 def bookInstance = Book . get(id)
48+ bookInstanceRedirectIfItsNull(id, bookInstance)
49+ }
50+
51+ private def bookInstanceRedirectIfItsNull (Long id , Book bookInstance ) {
5452 if (! bookInstance) {
5553 flash. message = message(code : ' default.not.found.message' , args : [message(code : ' book.label' , default : ' Book' ), id])
5654 redirect(action : " list" )
@@ -68,14 +66,12 @@ class BookController {
6866 return
6967 }
7068
71- if (version != null ) {
72- if (bookInstance. version > version) {
69+ if (version != null && bookInstance. version > version) {
7370 bookInstance. errors. rejectValue(" version" , " default.optimistic.locking.failure" ,
7471 [message(code : ' book.label' , default : ' Book' )] as Object [],
7572 " Another user has updated this Book while you were editing" )
7673 render(view : " edit" , model : [bookInstance : bookInstance])
7774 return
78- }
7975 }
8076
8177 bookInstance. properties = params
0 commit comments