6.2.2.5 表单和字段 - Reference Documentation
Authors: Graeme Rocher, Peter Ledbrook, Marc Palmer, Jeff Brown, Luke Daley, Burt Beckwith
Version: null
6.2.2.5 表单和字段
Form Basics
GSP supports many different tags for working with HTML forms and fields, the most basic of which is the form tag. This is a controller/action aware version of the regular HTML form tag. Theurl attribute lets you specify which controller and action to map to:<g:form name="myForm" url="[controller:'book',action:'list']">...</g:form>
myForm that submits to the BookController's list action. Beyond that all of the usual HTML attributes apply.
表单基础
GSP有很多不同的标签来支持HTML表单和字段,不过最基础的还是form标签。常规的HTML表单标签支持controller/action属性,而url属性让你以映射(map)的方式来指定controller和action:<g:form name="myForm" url="[controller:'book',action:'list']">...</g:form>
myForm表单,它将会提交到BookController控制器的list操作。此外HTML的所有通用属性都可以使用。Form Fields
In addition to easy construction of forms, GSP supports custom tags for dealing with different types of fields, including:- textField - For input fields of type 'text'
- passwordField - For input fields of type 'password'
- checkBox - For input fields of type 'checkbox'
- radio - For input fields of type 'radio'
- hiddenField - For input fields of type 'hidden'
- select - For dealing with HTML select boxes
<g:textField name="myField" value="${myValue}" />表单字段
除了轻松地构造表单之外,GSP自定义的标签支持不同的字段类型,包括:- textField - 针对类型是'text'的输入字段
- passwordField - 针对类型是'password'的输入字段
- checkBox - 针对类型是'checkbox'的输入字段
- radio - 针对类型是'radio'的输入字段
- hiddenField - 针对类型是'hidden'的输入字段
- select - 针对HTML的下拉框(select boxes)
<g:textField name="myField" value="${myValue}" />Multiple Submit Buttons
The age old problem of dealing with multiple submit buttons is also handled elegantly with Grails using the actionSubmit tag. It is just like a regular submit, but lets you specify an alternative action to submit to:<g:actionSubmit value="Some update label" action="update" />多个提交按钮
处理多个提交按钮这一个古老的问题,也得到优雅的解决,那就是使用Grails的actionSubmit标签。跟常规的提交类似,只不过你可以指定另外一个操作来提交:<g:actionSubmit value="Some update label" action="update" />
