Apache Struts 2 Documentation > Home > Guides > Tag Developers Guide > Struts Tags > Tag Reference > UI Tag Reference > submit
Added by digi9ten, last edited by Don Brown on Jan 06, 2007  (view change)

Please make sure you have read the Tag Syntax document and understand how tag attribute syntax works.

Description

Render a submit button. The submit tag is used together with the form tag to provide asynchronous form submissions. The submit can have three different types of rendering:

  • input: renders as html <input type="submit"...>
  • image: renders as html <input type="image"...>
  • button: renders as html <button type="submit"...>
Please note that the button type has advantages by adding the possibility to seperate the submitted value from the text shown on the button face, but has issues with Microsoft Internet Explorer at least up to 6.0

THE FOLLOWING IS ONLY VALID WHEN AJAX IS CONFIGURED

  • href
  • errorText
  • listenTopics
  • notifyTopics
  • executeScripts
  • loadingText
  • listenTopics
  • handler
  • formId
  • formFilter
  • targets
  • showErrorTransportText
  • targets
  • indicator
'resultDivId' Deprecated. Use targets.

'targets' is a list of element ids whose content will be updated with the text returned from request.

'errorText' is the text that will be displayed when there is an error making the request.

'onLoadJS' Deprecated. Use 'notifyTopics'.

'preInvokeJS' Deprecated. Use 'notifyTopics'.

'executeScripts' if set to true will execute javascript sections in the returned text.

'loadingText' is the text that will be displayed on the 'targets' elements while making the request.

'handler' is the name of the function that will take care of making the AJAX request. Dojo's widget and dom node are passed as parameters).

'formId' is the id of the html form whose fields will be seralized and passed as parameters in the request.

'formFilter' is the name of a function which will be used to filter the fields that will be seralized. This function takes as a parameter the element and returns true if the element should be included.

'listenTopics' comma separated list of topics names, that will trigger a request 'indicator' element to be shown while the request executing 'showErrorTransportText': whether errors should be displayed (on 'targets')

'notifyTopics' comma separated list of topics names, that will be published. Three parameters are passed:

  • data: html or json object when type='load' or type='error'
  • type: 'before' before the request is made, 'load' when the request succeeds, or 'error' when it fails
  • request: request javascript object, when type='load' or type='error'

This tag works with all themes, but has special importance when combined with the form tag in the ajax theme. Please read up on the ajax theme for more information.

Parameters

Name

Required

Default

Evaluated

Type

Description

accesskey false true String Set the html accesskey attribute on rendered html element
action false true String Set action attribute.
align false true String HTML align attribute.
cssClass false true String The css class to use for element
cssStyle false true String The css style definitions for element ro use
disabled false true String Set the html disabled attribute on rendered html element
errorText false true String The text to display to the user if the is an error fetching the content
executeScripts false false true Boolean Javascript code in the fetched content will be executed
formFilter false true String Function name used to filter the fields of the form.
formId false true String Form id whose fields will be serialized and passed as parameters
handler false true String Javascript function name that will make the request
href false true String The URL to call to obtain the content. Note: If used with ajax context, the value must be set as an url tag value.
id false true String id for referencing element. For UI and form tags it will be used as HTML id attribute
indicator false true String Set indicator
key false true String Set the key (name, value, label) for this particular component
label false true String Label expression used for rendering a element specific label
labelposition false true String Define label position of form element (top/left)
listenTopics false true String Topic that will trigger the remote call
loadingText false Loading... true String Text to be shown while content is being fetched
method false true String Set method attribute.
name false true String The name to set for element
notifyTopics false true String Topics that will published when the remote call completes
onLoadJS false true String Deprecated. Use 'notifyTopics'. Javascript code execute after reload
onblur false true String Set the html onblur attribute on rendered html element
onchange false true String Set the html onchange attribute on rendered html element
onclick false true String Set the html onclick attribute on rendered html element
ondblclick false true String Set the html ondblclick attribute on rendered html element
onfocus false true String Set the html onfocus attribute on rendered html element
onkeydown false true String Set the html onkeydown attribute on rendered html element
onkeypress false true String Set the html onkeypress attribute on rendered html element
onkeyup false true String Set the html onkeyup attribute on rendered html element
onmousedown false true String Set the html onmousedown attribute on rendered html element
onmousemove false true String Set the html onmousemove attribute on rendered html element
onmouseout false true String Set the html onmouseout attribute on rendered html element
onmouseover false true String Set the html onmouseover attribute on rendered html element
onmouseup false true String Set the html onmouseup attribute on rendered html element
onselect false true String Set the html onselect attribute on rendered html element
preInvokeJS false true String Deprecated. Use 'notifyTopics'. Javascript code execute before reload
required false false true Boolean If set to true, the rendered element will indicate that input is required
requiredposition false true String Define required position of required form element (left|right)
showErrorTransportText false true true Boolean Set whether errors will be shown or not
src false true String Supply an image src for image type submit button. Will have no effect for types input and button.
tabindex false true String Set the html tabindex attribute on rendered html element
targets false true String Comma delimited list of ids of the elements whose content will be updated
template false true String The template (other than default) to use for rendering the element
templateDir false true String The template directory.
theme false true String The theme to use for the element. This tag will usually use the ajax theme.
title false true String Set the html title attribute on rendered html element
tooltip false true String Set the tooltip of this particular component
tooltipConfig false true String Set the tooltip configuration
type false input true String The type of submit to use. Valid values are input, button and image.
value false true String Preset the value of input element.

Examples

Example 1

<s:submit value="%{'Submit'}" />

Example 2

Render an image submit:
<s:submit type="image" value="%{'Submit'}" label="Submit the form" src="submit.gif"/>

Example 3

Render an button submit:
<s:submit type="button" value="%{'Submit'}" label="Submit the form"/>

Example 4

Show the results in another div. If you want your results to be shown in a div, use the resultDivId where the id is the id of the div you want them shown in. This is an inner HTML approah. Your results get jammed into the div for you. Here is a sample of this approach:

Remote form replacing another div:
<div id='two' style="border: 1px solid yellow;">Initial content</div>
<s:form
      id='theForm2'
      cssStyle="border: 1px solid green;"
      action='/AjaxRemoteForm.action'
      method='post'
      theme="ajax">

  <input type='text' name='data' value='Struts User' />
  <s:submit value="GO2" theme="ajax" resultDivId="two" />

</s:form >