org.apache.struts2.components
Class Submit

java.lang.Object
  extended by org.apache.struts2.components.Component
      extended by org.apache.struts2.components.UIBean
          extended by org.apache.struts2.components.FormButton
              extended by org.apache.struts2.components.Submit

public class Submit
extends FormButton

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:

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'}" />
 
 
 
 Render an image submit:
 <s:submit type="image" value="%{'Submit'}" label="Submit the form" src="submit.gif"/>
 
 
 
 Render an button submit:
 <s:submit type="button" value="%{'Submit'}" label="Submit the form"/>
 
 
THE FOLLOWING IS ONLY VALID WHEN AJAX IS CONFIGURED The remote form has three basic modes of use, using the resultDivId, the notifyTopics, or the onLoadJS. You can mix and match any combination of them to get your desired result. All of these examples are contained in the Ajax example webapp. Lets go through some scenarios to see how you might use it: 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 >
 
 
Notify other controls(divs) of a change. Using an pub-sub model you can notify others that your control changed and they can take the appropriate action. Most likely they will execute some action to refresh. The notifyTopics does this for you. You can have many topic names in a comma delimited list. eg: notifyTopics="newPerson, dataChanged" . Here is an example of this approach:
 
 <s:form id="frm1" action="newPersonWithXMLResult" theme="ajax"  >
     <s:textfield label="Name" name="person.name" value="person.name" size="20" required="true" />
     <s:submit id="submitBtn" value="Save" theme="ajax"  cssClass="primary"  notifyTopics="personUpdated, systemWorking" />
 </s:form >
 
 <s:div href="/listPeople.action" theme="ajax" errorText="error opps"
         loadingText="loading..." id="cart-body" >
     <s:action namespace="" name="listPeople" executeResult="true" />
 </s:div>
 
 
Massage the results with JavaScript. Say that your result returns some h appy XML and you want to parse it and do lots of cool things with it. The way to do this is with a onLoadJS handler. Here you provide the name of a JavaScript function to be called back with the result and the event type. The only key is that you must use the variable names 'data' and 'type' when defining the callback. For example: onLoadJS="myFancyDancyFunction(data, type)". While I talked about XML in this example, your not limited to XML, the data in the callback will be exactly whats returned as your result. Here is an example of this approach:
 
 <script language="JavaScript" type="text/javascript">
     function doGreatThings(data, type) {
         //Do whatever with your returned fragment... 
         //Perhapps.... if xml...
               var xml = dojo.xml.domUtil.createDocumentFromText(data);
               var people = xml.getElementsByTagName("person");
               for(var i = 0;i < people.length; i ++){
                   var person = people[i];
                   var name = person.getAttribute("name")
                   var id = person.getAttribute("id")
                   alert('Thanks dude. Person: ' + name + ' saved great!!!');
               }

     }
 </script>

 <s:form id="frm1" action="newPersonWithXMLResult" theme="ajax"  >
     <s:textfield label="Name" name="person.name" value="person.name" size="20" required="true" />
     <s:submit id="submitBtn" value="Save" theme="ajax"  cssClass="primary"  onLoadJS="doGreatThings(data, type)" />
 </s:form>
 
 


Field Summary
protected  java.lang.String listenTopics
           
protected  java.lang.String notifyTopics
           
protected  java.lang.String onLoadJS
           
protected  java.lang.String preInvokeJS
           
protected  java.lang.String resultDivId
           
protected  java.lang.String src
           
static java.lang.String TEMPLATE
           
 
Fields inherited from class org.apache.struts2.components.FormButton
action, align, method, type
 
Fields inherited from class org.apache.struts2.components.UIBean
accesskey, cssClass, cssStyle, disabled, label, labelPosition, name, onblur, onchange, onclick, ondblclick, onfocus, onkeydown, onkeypress, onkeyup, onmousedown, onmousemove, onmouseout, onmouseover, onmouseup, onselect, request, required, requiredposition, response, tabindex, template, templateDir, templateSuffix, theme, title, tooltip, tooltipConfig, value
 
Fields inherited from class org.apache.struts2.components.Component
COMPONENT_STACK, id, parameters, stack
 
Constructor Summary
Submit(com.opensymphony.xwork2.util.OgnlValueStack stack, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
           
 
Method Summary
 void evaluateExtraParams()
           
 void evaluateParams()
           
protected  java.lang.String getDefaultTemplate()
          A contract that requires each concrete UI Tag to specify which template should be used as a default.
 void setLabel(java.lang.String label)
          Supply a submit button text apart from submit value.
 void setListenTopics(java.lang.String listenTopics)
          Set listenTopics attribute.
 void setNotifyTopics(java.lang.String notifyTopics)
          Topic names to post an event to after the form has been submitted.
 void setOnLoadJS(java.lang.String onLoadJS)
          Javascript code that will be executed after the form has been submitted.
 void setPreInvokeJS(java.lang.String preInvokeJS)
          Javascript code that will be executed before invokation.
 void setResultDivId(java.lang.String resultDivId)
          The id of the HTML element to place the result (this can the the form's id or any id on the page.
 void setSrc(java.lang.String src)
          Supply an image src for image type submit button.
protected  boolean supportsImageType()
          Indicate whether the concrete button supports the type "image".
 
Methods inherited from class org.apache.struts2.components.FormButton
populateComponentHtmlId, setAction, setAlign, setMethod, setType
 
Methods inherited from class org.apache.struts2.components.UIBean
addFormParameter, buildTemplateName, enableAncestorFormCustomOnsubmit, end, escape, evaluateNameValue, getTemplate, getTemplateDir, getTheme, getTooltipConfig, getValueClassType, mergeTemplate, setAccesskey, setCssClass, setCssStyle, setDisabled, setLabelposition, setName, setOnblur, setOnchange, setOnclick, setOndblclick, setOnfocus, setOnkeydown, setOnkeypress, setOnkeyup, setOnmousedown, setOnmousemove, setOnmouseout, setOnmouseover, setOnmouseup, setOnselect, setRequired, setRequiredposition, setTabindex, setTemplate, setTemplateDir, setTheme, setTitle, setTooltip, setTooltipConfig, setValue
 
Methods inherited from class org.apache.struts2.components.Component
addAllParameters, addParameter, altSyntax, copyParams, determineActionURL, determineNamespace, end, fieldError, findAncestor, findString, findString, findValue, findValue, findValue, getComponentStack, getId, getParameters, getStack, popComponentStack, setId, start, toString, usesBody
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TEMPLATE

public static final java.lang.String TEMPLATE
See Also:
Constant Field Values

resultDivId

protected java.lang.String resultDivId

onLoadJS

protected java.lang.String onLoadJS

notifyTopics

protected java.lang.String notifyTopics

listenTopics

protected java.lang.String listenTopics

preInvokeJS

protected java.lang.String preInvokeJS

src

protected java.lang.String src
Constructor Detail

Submit

public Submit(com.opensymphony.xwork2.util.OgnlValueStack stack,
              javax.servlet.http.HttpServletRequest request,
              javax.servlet.http.HttpServletResponse response)
Method Detail

getDefaultTemplate

protected java.lang.String getDefaultTemplate()
Description copied from class: UIBean
A contract that requires each concrete UI Tag to specify which template should be used as a default. For example, the CheckboxTab might return "checkbox.vm" while the RadioTag might return "radio.vm". This value not begin with a '/' unless you intend to make the path absolute rather than relative to the current theme.

Specified by:
getDefaultTemplate in class UIBean
Returns:
The name of the template to be used as the default.

evaluateParams

public void evaluateParams()
Overrides:
evaluateParams in class UIBean

evaluateExtraParams

public void evaluateExtraParams()
Overrides:
evaluateExtraParams in class FormButton

supportsImageType

protected boolean supportsImageType()
Indicate whether the concrete button supports the type "image".

Specified by:
supportsImageType in class FormButton
Returns:
true to indicate type image is supported.

setResultDivId

public void setResultDivId(java.lang.String resultDivId)
The id of the HTML element to place the result (this can the the form's id or any id on the page.


setOnLoadJS

public void setOnLoadJS(java.lang.String onLoadJS)
Javascript code that will be executed after the form has been submitted. The format is onLoadJS='yourMethodName(data,type)'. NOTE: the words data and type must be left like that if you want the event type and the returned data.


setNotifyTopics

public void setNotifyTopics(java.lang.String notifyTopics)
Topic names to post an event to after the form has been submitted.


setListenTopics

public void setListenTopics(java.lang.String listenTopics)
Set listenTopics attribute.


setPreInvokeJS

public void setPreInvokeJS(java.lang.String preInvokeJS)
Javascript code that will be executed before invokation. The format is preInvokeJS='yourMethodName(data,type)'.


setLabel

public void setLabel(java.lang.String label)
Supply a submit button text apart from submit value. Will have no effect for input type submit, since button text will always be the value parameter. For the type image, alt parameter will be set to this value.

Overrides:
setLabel in class UIBean

setSrc

public void setSrc(java.lang.String src)
Supply an image src for image type submit button. Will have no effect for types input and button.



Copyright © 2000-2006 Apache Software Foundation. All Rights Reserved.