views:

281

answers:

1

Using markup with the render is not adding the form tag.

I tried this with contentType "text/html", "txt/xml" and it does not work.

I have this in my controller:

 def myTest= {
    render(contentType: "text/plain") {
     div(id:"myDiv") {
   p "somess text inside the div"
   form (action:'get') {
       p "inside form"
   }
     }
 }

And I'm getting this:

<div id='myDiv'><p>somess text inside the div</p><p>inside form</p></div>

I want this:

<div id='myDiv'><p>somess text inside the div</p><form><p>inside form</p></form></div>

Does anybody know why is not adding the form and how to add it?

Thanks,

Federico

+2  A: 

i found this problem earlier and the work around was to use the builder directly

def test = {
    def sw = new StringWriter()
    def b = new MarkupBuilder(sw)
    b.html(contentType: "text/html") {
        div(id: "myDiv") {
            p "somess text inside the div"
            b.form(action: 'get') {
                p "inside form"
            }
        }

    }
    render sw
}

will render the following HTML

<html contentType='text/html'>
  <div id='myDiv'>
    <p>somess text inside the div</p>
    <form action='get'>
      <p>inside form</p>
    </form>
  </div>
</html>
Aaron Saunders
Aaron is right, calling form on it's own is probably clashing with the g:form taglib method that is dynamically added to all controllers
leebutts