0

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

David B
  • 3,269
  • 12
  • 48
  • 80

2 Answers2

2

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')}"
}
peddn
  • 98
  • 1
  • 8
1

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')}"
 }
peddn
  • 98
  • 1
  • 8
  • Thanks. But is there a way to format single digit [0-9] to make it format into two digit `0\d`? Thanks. – David B Jun 28 '12 at 12:13