How to write a set for g: select tag

enter image description hereHow to write parameters so that I can generate them in HTML select? The problem with this "options" requires a set, not an array

That is all that I have. I know that the naming convention is bad, and I will fix it, but now I have been dealing with this problem for several days now.

Controller class

import org.springframework.dao.DataIntegrityViolationException
import grails.plugin.mail.*

class EmailServiceController {

    static defaultAction = "contactService"

def contactService() {
    def options = new ArrayList()
    options.push("Qestions about service")
    options.push("Feedback on performed service")
    options.push("Other")
    options.push("Why am I doing this")
    options
}

    def send() {
        sendMail(){
            to "mygroovytest@gmail.com"
            from params.email
            subject params.subject
            body params.information
        }
    }
}

Domain class

class EmailService {

    static constraints = {
    }
}

g: select call from gsp

<g:select name = "subject" from = "${options}" noSelection="Topic"/>

also tried the following with "$ {selectOptions}" instead of "$ {options}" with no luck

def selectOptions() {
    def options = new ArrayList()
    options.push("Qestions about service": "QAS")
    options.push("Feedback on performed service":"FoPS")
    options.push("Other":"Other")
    options.push("Why am I doing this":"WHY")
    return options
}
+2
source share
3 answers

Well, I think I might know what was going on here. The missing part of the question is the gsp call. Here is a suitable way:

class EmailServiceController {

  def contactService() {
    def options = ["Qestions about service", "Feedback on performed service", "Other"]
    // assumes you are going to render contactService.gsp
    // you have to push the options to the view in the request
    [options:options]
  }

}

And then in contactService.gsp you will have:

<g:select name="subject" from="${options}" noSelection="['Topic': 'Topic']"/>
+6
source

options , . . . , :

def selectOptions() {
    def options = [:]
    options["Qestions about service"] = "QAS"
    options["Feedback on performed service"] = "FoPS"
    [options:options]
}

, :

<g:select name="subject" from="${options.entrySet()}" 
    optionValue="key" optionKey="value"
    noSelection="['Topic': 'Topic']"/>
+3

You need to use double quotes in your tags, not single quotes. With single quotes, you just pass in a string that looks like '${options}'instead of passing a GString with a value options.

<g:select name="subject" from="${options}" noSelection="Topic"/>

Also, if you invoke an action contactService, you need return optionsto return instead options.push("Other"). push()returns a boolean value, which means that the implicit return contactServiceis a boolean result push()instead options.

0
source

All Articles