Note |
---|
Please make sure you have read the Tag Syntax document and understand how tag attribute syntax works. |
Description
Wiki Markup |
---|
{snippet:id=javadoc|javadoc=true|url=org.apache.struts2.components.Form} |
Parameters
Wiki Markup |
---|
{snippet:id=tagattributes|javadoc=false|url=struts2-tags/form.html} |
Examples
Wiki Markup |
---|
{snippet:id=example|lang=xml|javadoc=true|url=org.apache.struts2.components.Form} |
Validation
There are two flavours Client Side Validation, depending on the theme you are using (xhtml, ajax, etc). If you are using the xhtml theme or css_xhtml theme, pure client side validation will be used. If you are using the ajax theme, a special AJAX-based validation will take place. Read the Client Side Validation docs for more information.
Talk generally about the form, behaviors, etc. Mention theme-specific notes as well.
Attribute | Type | Required | Default | Theme | Description |
---|---|---|---|---|---|
action | String | Yes | N/A | simple | ... |
namespace | String | No | The current namespace | simple | ... |
validate | boolean | No | false | xhtml | ... |
form
Attribute | Type | Required | Default | Description |
---|---|---|---|---|
id | string | FALSE | action attribute |
|
name | string | FALSE | action attribute |
|
action | string | FALSE |
|
|
target | string | FALSE |
|
|
enctype | string | FALSE |
|
|
method | string | FALSE |
|
|
namespace | string | FALSE | global namespace: """ |
|
onsubmit | string | FALSE |
|
|
validate | boolean | FALSE |
|
|
name | string | TRUE |
|
|
value | string | FALSE |
|
|
required | boolean | FALSE |
|
|
disabled | boolean | FALSE |
|
|
theme | string | FALSE |
|
|
template | string | FALSE |
|
|
cssClass | string | FALSE |
|
|
cssStyle | string | FALSE |
|
|
label | string | FALSE |
|
|
labelposition | string | FALSE |
|
|
tabindex | string | FALSE |
|
|
onclick | string | FALSE |
|
|
ondblclick | string | FALSE |
|
|
onmousedown | string | FALSE |
|
|
onmouseup | string | FALSE |
|
|
onmouseover | string | FALSE |
|
|
onmousemove | string | FALSE |
|
|
onmouseout | string | FALSE |
|
|
onfocus | string | FALSE |
|
|
onblur | string | FALSE |
|
|
onkeypress | string | FALSE |
|
|
onkeydown | string | FALSE |
|
|
onselect | string | FALSE |
|
|
onchange | string | FALSE |
|
|
The remote form allows the form to be submitted without the page being refreshed. The results from the form can be inserted into any HTML element on the page.
Attributes
To ajax enable the form, the ww:form component must be used, specifying a theme="ajax". Additionally, the ww:submit component must be used. The ajax-specific attributes of ww:submit are:
name | Description |
---|---|
resultDivId (required) | The id of the HTML element to place the result (this can the the form's id or any id on the page |
notifyTopics | Topic names to post an event to after the form has been submitted |
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. |
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:
...
Code Block |
---|
Remote form replacing another div:
<div id='two' style="border: 1px solid yellow;">Initial content</div>
<ww:form
id='theForm2'
cssStyle="border: 1px solid green;"
action='/AjaxRemoteForm.action'
method='post'
theme="ajax">
<input type='text' name='data' value='WebWork User'>
<ww:submit value="GO2" theme="ajax" resultDivId="two"/>
</ww:form>
|
...
Code Block |
---|
<ww:form id="frm1" action="newPersonWithXMLResult" theme="ajax" >
<ww:textfield label="'Name'" name="'person.name'" value="person.name" size="20" required="true" />
<ww:submit id="submitBtn" value="Save" theme="ajax" cssClass="primary" notifyTopics="personUpdated, systemWorking" />
</ww:form>
<ww:div href="/listPeople.action" theme="ajax" errorText="error opps"
loadingText="loading..." id="cart-body" >
<ww:action namespace="" name="listPeople" executeResult="true" />
</ww:div>
|
...