actionSubmit
目的 Purpose
Generates a submit button that maps to a specific action, which lets you have multiple submit buttons in a single form. JavaScript event handlers can be added using the same parameter names as in HTML.使用例 Examples
<g:actionSubmit value="Update" /><!--'Update' is action, label is 'Some update label'--> <g:actionSubmit value="Some update label" action="Update" /><!--label derived from message bundle--> <g:actionSubmit value="${message(code:'label.update')}" action="Update" /><g:actionSubmit value="Delete" /><g:actionSubmit value="DeleteAll" onclick="return confirm('Are you sure???')" />
詳細 Description
属性 Attributes
value
(required) - The caption of the button and name of action when not explicitly defined.action
(optional) - The name of the action to be executed, otherwise it is derived from the value.
actionSubmit
tag. In such cases, it is probably a good idea to use custom URL mappings.URL Mappings
The implementation of theactionSubmit
tag means that it does not sit entirely comfortably with URL mappings, particularly the default one. The reason for this is that URL mappings work on the URL of the request, but actionSubmit
uses a parameter to determine the action to execute. This means that there is a mismatch between any action name in the URL mapping, and the name of the actual action executed.Take this simple case with the default URL mapping:class UrlMappings { static mappings = { "/$controller/$action?/$id?"{ constraints { // apply constraints here } } } }
<g:form controller="test"> <g:actionSubmit value="Submit" action="success"/> </g:form>
<form>
element will either be ".../test" or ".../test/index" (assuming "index" is the default action) depending on your version of Grails. Note that neither version includes "success" in the URL, and when you click on the submit button the URL in the browser will be without "success" too.This isn't too much of a problem when the form URL does not include an action name, but if you have a version of Grails that appends the name of the default action, or you specify an action in your <g:form>
tag, then you should probably use a custom URL mapping to hide the action name:"/test/submit" { controller = "test" action = "index" }
<g:form>
tag.Also note that this tag relies on the multipart resolver to be able to inspect parameters included with mulitpart requests. If you disable the resolver by setting grails.disableCommonsMultipart
to true in Config.groovy
, actionSubmit
will not work.