Why use <g:textField /> in Grails?

五迷三道 提交于 2019-12-05 16:30:09

问题


What is the reason to use g:textField in Grails if you're already familiar with standard HTML form tags?

If I understand correctly the following two markup alternatives are equivalent:

<input type="text" name="name" value="${params.name}" id="name" />
<g:textField name="name" value="${params.name}" />

Are there any circumstances under which using g:textField would add value? Am I missing something?


回答1:


The textField tag is provided as a convenience (slightly shorter than writing the HTML input) and is there to provide a full set of form tags. Personally I prefer to write as much plain HTML as possible in my Grails views and only tend to use the tags that really offer a benefit such as the form tag. I have not found an instance where using textField would have added any value outside of requiring a few less characters to type.




回答2:


<g:textField /> is not shorter as plain text field tag, except id attribute will be attached automatically.

However, I recommend you to use customized tags associating the bean values with input fields. That shortens the code a lot. For more information you can read http://www.jtict.com/blog/shorter-grails-textfield/ Also you can find useful stuff in Form Helper Plugin



来源:https://stackoverflow.com/questions/1055574/why-use-gtextfield-in-grails

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!