0
votes

In some grails code I've been reading, I see a function called "field()" that seems to do the following;

given an object of the form

def a = [a:b, c:d, e:123]

field(a) will produce the string

a="b" c="d" e="123"

i.e., it translates these name value pairs into a form sutiable for an html/xhtml/xml element.

I've searched the grails documentation for this function, and can't find it described anywhere. Where does it come from? Is it part of one of those other frameworks, like SiteMesh, that get magically included into Grails? (Though I can't find it in the SiteMesh docs, either!)

I tried it in my code, and it works, but it occasionally throws an exception and I want to see the real definition of this function and how it is supposed to be used.

1

1 Answers

1
votes

It's a part of Grails tag lib, located in this file:

src/java/org/codehaus/groovy/grails/plugins/web/taglib/FormTagLib.groovy

Here's its code:

/**
  * A general tag for creating fields
  */
def field = {attrs ->
    resolveAttributes(attrs)
    attrs.id = attrs.id ? attrs.id : attrs.name
    out << "<input type=\"${attrs.remove('type')}\" "
    outputAttributes(attrs)
    out << "/>"
}