简体   繁体   中英

Grails Taglib G:SELECT

I am new to the Grails platform and became interested in the TagLib component. I have this application wherein I am to create a time select [24-hour format selection] made of two <select> tag: hour and time. So far I have coded my theory in this manner.

def timePicker = { attrs ->
   out << "<g:select name='" + attrs['name'] + ".hour' from='${00..21}' />"
   out << "<g:select name='" + attrs['name'] + ".minute' from='${00..59}' />" 
}

However I can't display it in the page but it display the content of out in the webpage itself which is wrong. How can I have two <select> display properly on the .gsp by TagLib? Am i going to write it in the conventional <select> accompanied with <option> statements, or am going to utilize the g.select(attrs) syntax?

Thanks

you could use something like this:

def timePicker = { attrs ->
    def hours = 0..21
    def stringHours = hours.collect{ String.format('%02d', it) }

    def minutes = 0..59
    def stringMinutes = minutes.collect{ String.format('%02d', it) }

    out << "${select(from: stringHours, name: attrs.name + '.hour')}"
    out << "${select(from: stringMinutes, name: attrs.name + '.minute')}"
}

You can use a method call in GSP only:

def timePicker = { attrs ->
    out << "${select(from: 00..21, name: attrs.name + '.hour')}"
    out << "${select(from: 00..59, name: attrs.name + '.minute')}"
 }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM