FileDocCategorySizeDatePackage
Submit.javaAPI DocExample13411Mon Jul 23 13:26:36 BST 2007org.apache.struts2.components

Submit

public class Submit extends FormButton implements RemoteUICallBean
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

Examples


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


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


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

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')

'showLoadingText' show loading text 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'
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 >

Fields Summary
private static final Log
LOG
public static final String
TEMPLATE
protected String
href
protected String
errorText
protected String
executeScripts
protected String
loadingText
protected String
listenTopics
protected String
handler
protected String
formId
protected String
formFilter
protected String
src
protected String
notifyTopics
protected String
showErrorTransportText
protected String
indicator
protected String
showLoadingText
protected String
beforeLoading
protected String
afterLoading
protected String
targets
Constructors Summary
public Submit(com.opensymphony.xwork2.util.ValueStack stack, HttpServletRequest request, HttpServletResponse response)


           
        super(stack, request, response);
    
Methods Summary
public booleanend(java.io.Writer writer, java.lang.String body)
Overrides to be able to render body in a template rather than always before the template

        evaluateParams();
        try {
            addParameter("body", body);
            
            mergeTemplate(writer, buildTemplateName(template, getDefaultTemplate()));
        } catch (Exception e) {
            LOG.error("error when rendering", e);
        }
        finally {
            popComponentStack();
        }

        return false;
    
public voidevaluateExtraParams()

        super.evaluateExtraParams();

        if (href != null)
            addParameter("href", findString(href));
        if (errorText != null)
            addParameter("errorText", findString(errorText));
        if (loadingText != null)
            addParameter("loadingText", findString(loadingText));
        if (afterLoading != null)
            addParameter("afterLoading", findString(afterLoading));
        if (beforeLoading != null)
            addParameter("beforeLoading", findString(beforeLoading));
        if (executeScripts != null)
            addParameter("executeScripts", findValue(executeScripts, Boolean.class));
        if (listenTopics != null)
            addParameter("listenTopics", findString(listenTopics));
        if (notifyTopics != null)
            addParameter("notifyTopics", findString(notifyTopics));
        if (handler != null)
            addParameter("handler", findString(handler));
        if (formId != null)
            addParameter("formId", findString(formId));
        if (formFilter != null)
            addParameter("formFilter", findString(formFilter));
        if (src != null)
            addParameter("src", findString(src));
        if (indicator != null)
            addParameter("indicator", findString(indicator));
        if (targets != null)
            addParameter("targets", findString(targets));
        if (showLoadingText != null)
            addParameter("showLoadingText", findString(showLoadingText));
    
public voidevaluateParams()

        if ((key == null) && (value == null)) {
            value = "Submit";
        }

        if (((key != null)) && (value == null)) {
            this.value = "%{getText('"+key +"')}";
        }

        super.evaluateParams();
    
protected java.lang.StringgetDefaultTemplate()

        return TEMPLATE;
    
public voidsetAfterLoading(java.lang.String afterLoading)

        this.afterLoading = afterLoading;
    
public voidsetBeforeLoading(java.lang.String beforeLoading)

        this.beforeLoading = beforeLoading;
    
public voidsetErrorText(java.lang.String errorText)

        this.errorText = errorText;
    
public voidsetExecuteScripts(java.lang.String executeScripts)

        this.executeScripts = executeScripts;
    
public voidsetFormFilter(java.lang.String formFilter)

        this.formFilter = formFilter;
    
public voidsetFormId(java.lang.String formId)

        this.formId = formId;
    
public voidsetHandler(java.lang.String handler)

        this.handler = handler;
    
public voidsetHref(java.lang.String href)

        this.href = href;
    
public voidsetIndicator(java.lang.String indicator)

        this.indicator = indicator;
    
public voidsetListenTopics(java.lang.String listenTopics)

        this.listenTopics = listenTopics;
    
public voidsetLoadingText(java.lang.String loadingText)

        this.loadingText = loadingText;
    
public voidsetNotifyTopics(java.lang.String notifyTopics)

        this.notifyTopics = notifyTopics;
    
public voidsetShowErrorTransportText(java.lang.String showErrorTransportText)

        this.showErrorTransportText = showErrorTransportText;
    
public voidsetShowLoadingText(java.lang.String showLoadingText)

        this.showLoadingText = showLoadingText;
    
public voidsetSrc(java.lang.String src)

        this.src = src;
    
public voidsetTargets(java.lang.String targets)

        this.targets = targets;
    
public voidsetTheme(java.lang.String theme)

        super.setTheme(theme);
    
protected booleansupportsImageType()
Indicate whether the concrete button supports the type "image".

return
true to indicate type image is supported.

        return true;