开发者

Cannot render form tag using 'render' in Grails Controller

开发者 https://www.devze.com 2022-12-08 17:31 出处:网络
Using markup with the render is not adding the form tag. I tried this with contentType \"text/h开发者_开发技巧tml\", \"txt/xml\" and it does not work.

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

I tried this with contentType "text/h开发者_开发技巧tml", "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


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>
0

精彩评论

暂无评论...
验证码 换一张
取 消