porno porno rokettube
Results 1 to 2 of 2

Thread: Having problem with <g:select in gsp

  1. #1
    Junior Member
    Join Date
    Dec 2012
    Posts
    7

    Having problem with <g:select in gsp

    Hi
    I have simple test example with the following domain.

    class Client {

    LTitle ltitle
    String firstname
    String surname

    Date dateCreated
    Date lastUpdated
    String updatedBy
    static constraints = {
    }

    } // end Client

    class LTitle {
    int titleId
    String title

    static constraints = {
    title blank: false, nullable: false
    }
    }


    in gsp

    <div class="fieldcontain ${hasErrors(bean: clientInstance, field: 'title', 'error')} required">
    <label for="title">
    <g:message code="client.title.label" default="Title" />
    <span class="required-indicator">*</span>
    </label>
    <g:select id="titleId" name="titleId"
    from="${uk.co.lbl.comman.LTitle.list().sort{ it.title }}"
    optionKey="id" optionValue="title"
    required="" value="${clientInstance?.ltitle?.id}"
    class="many-to-one"/>
    </div>

    Controller
    def create() {
    respond new Client(params)
    }

    @Transactional
    def save(Client clientInstance) {
    if (clientInstance == null) {
    notFound()
    return
    }

    if (clientInstance.hasErrors()) {
    respond clientInstance.errors, view:'create'
    return
    }

    clientInstance.save flush:true

    request.withFormat {
    form multipartForm {
    flash.message = message(code: 'default.created.message', args: [message(code: 'client.label', default: 'Client'), clientInstance.id])
    redirect clientInstance
    }
    '*' { respond clientInstance, [status: CREATED] }
    }
    }



    When I try to save form data. I am getting following error
    Property [ltitle] of class [class uk.co.lbl.client.Client] cannot be null

    Please can some one advice me.

    thanks
    ish

  2. #2
    Administrator dave's Avatar
    Join Date
    Mar 2010
    Location
    West Yorkshire, UK - Valencia Spain
    Posts
    110
    Try setting the name of your select from name="titleId" to name="title.id"

    Also see what params you receive in the save method to ensure you have what you expect.
    Connect with me on twitter : @davebrown1975 http://twitter.com/davebrown1975

    Web & Mobile Development by Tucanoo Solutions Ltd

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Forum Design by Tucanoo Solutions Ltd Grails Development Specialists.