small medium large xlarge

Back to: All Forums  Grails
Generic-user-small
26 Oct 2010, 12:05
Brian Adams (1 post)

Ver 1.0 of the book. Working on Chapter 7, Page 112.

After adding the hidden input and the statement I am now getting some errors that I cannot seem to resolve.

Error 500: Executing action [save] of controller [tekdays.MessageController] caused exception: groovy.lang.MissingMethodException: No signature of method: tekdays.TekEvent.get() is applicable for argument types: (java.lang.String, java.lang.String) values: [, 2] Possible solutions: get(java.lang.Object), getId(), getAt(java.lang.String), ident(), getLog(), getAll()
Servlet: grails
URI: /TekDays/grails/message/save.dispatch
Exception Message: No signature of method: tekdays.TekEvent.get() is applicable for argument types: (java.lang.String, java.lang.String) values: [, 2] Possible solutions: get(java.lang.Object), getId(), getAt(java.lang.String), ident(), getLog(), getAll() 
Caused by: No signature of method: tekdays.TekEvent.get() is applicable for argument types: (java.lang.String, java.lang.String) values: [, 2] Possible solutions: get(java.lang.Object), getId(), getAt(java.lang.String), ident(), getLog(), getAll() 
Class: Unknown 
At Line: [-1] 
Code Snippet:
package tekdays

class MessageController {

    static allowedMethods = [save: "POST", update: "POST", delete: "POST"]

    def index = {
        redirect(action: "list", params: params)
    }

    def list = {
        params.max = Math.min(params.max ? params.int('max') : 10, 100)
		def list
		def count
		def event = TekEvent.get(params.id)
		if(event){
			list = Message.findAllByEvent(event,params)
			count = Message.countByEvent(event)
		}
		else {
			list = Message.list(params)
			count = Message.count()
		}
        [messageInstanceList: list, messageInstanceTotal: count, event:event]
    }

    def create = {
		if( params."event.id" == null ) 
		    params."event.id" = params.eventId
		def messageInstance = new Message()
			messageInstance.properties = params
		return ['messageInstance':messageInstance]
    }

    def save = {
        def messageInstance = new Message(params)
        if (messageInstance.save(flush: true)) {
            flash.message = "${message(code: 'default.created.message', args: [message(code: 'message.label', default: 'Message'), messageInstance.id])}"
            redirect(action: "show", id: messageInstance.id)
        }
        else {
            render(view: "create", model: [messageInstance: messageInstance])
        }
    }

    def show = {
        def messageInstance = Message.get(params.id)
        if (!messageInstance) {
            flash.message = "${message(code: 'default.not.found.message', args: [message(code: 'message.label', default: 'Message'), params.id])}"
            redirect(action: "list")
        }
        else {
            [messageInstance: messageInstance]
        }
    }

    def edit = {
        def messageInstance = Message.get(params.id)
        if (!messageInstance) {
            flash.message = "${message(code: 'default.not.found.message', args: [message(code: 'message.label', default: 'Message'), params.id])}"
            redirect(action: "list")
        }
        else {
            return [messageInstance: messageInstance]
        }
    }

    def update = {
        def messageInstance = Message.get(params.id)
        if (messageInstance) {
            if (params.version) {
                def version = params.version.toLong()
                if (messageInstance.version > version) {
                    
                    messageInstance.errors.rejectValue("version", "default.optimistic.locking.failure", [message(code: 'message.label', default: 'Message')] as Object[], "Another user has updated this Message while you were editing")
                    render(view: "edit", model: [messageInstance: messageInstance])
                    return
                }
            }
            messageInstance.properties = params
            if (!messageInstance.hasErrors() && messageInstance.save(flush: true)) {
                flash.message = "${message(code: 'default.updated.message', args: [message(code: 'message.label', default: 'Message'), messageInstance.id])}"
                redirect(action: "show", id: messageInstance.id)
            }
            else {
                render(view: "edit", model: [messageInstance: messageInstance])
            }
        }
        else {
            flash.message = "${message(code: 'default.not.found.message', args: [message(code: 'message.label', default: 'Message'), params.id])}"
            redirect(action: "list")
        }
    }

    def delete = {
        def messageInstance = Message.get(params.id)
        if (messageInstance) {
            try {
                messageInstance.delete(flush: true)
                flash.message = "${message(code: 'default.deleted.message', args: [message(code: 'message.label', default: 'Message'), params.id])}"
                redirect(action: "list")
            }
            catch (org.springframework.dao.DataIntegrityViolationException e) {
                flash.message = "${message(code: 'default.not.deleted.message', args: [message(code: 'message.label', default: 'Message'), params.id])}"
                redirect(action: "show", id: params.id)
            }
        }
        else {
            flash.message = "${message(code: 'default.not.found.message', args: [message(code: 'message.label', default: 'Message'), params.id])}"
            redirect(action: "list")
        }
    }
}
Dklein_tiny_pragsmall
26 Oct 2010, 18:38
Dave Klein (34 posts)

Hi Brian,

It looks like params.event.id contains a list “[ , 2]” instead of a single id value. This can happen if there are two input field with the same name. Can you check to see if you have a second input with a name of “event.id”?

If that’s not the case, please post the contents of the message/create.gsp and I’ll take a closer look.

Thanks, Dave

You must be logged in to comment