Package org.apache.struts2.components
Class Form
java.lang.Object
org.apache.struts2.components.Component
org.apache.struts2.components.UIBean
org.apache.struts2.components.ClosingUIBean
org.apache.struts2.components.Form
Renders HTML an input form.
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.
NOTE:
The order / logic in determining the posting url of the generated HTML form is as follows:
- If the action attribute is not specified, then the current request will be used to determine the posting url
- If the action is given, Struts will try to obtain an ActionConfig. This will be successful if the action attribute is a valid action alias defined struts.xml.
- If the action is given and is not an action alias defined in struts.xml, Struts will used the action attribute as if it is the posting url, separting the namespace from it and using UrlHelper to generate the final url.
The client-side JS validate attribute is deprecated since 7.4.0 — use the html5 theme's
constraint attributes instead. Removed in 8.0.0.
Examples
<s:form ... />
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classWrap field validator, add visitor's field prefix to the field name. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected Stringprotected Stringprotected ActionValidatorManagerprotected Configurationprotected Stringprotected Stringprotected booleanprotected Stringprotected Stringprotected ObjectFactoryprotected Stringprotected Stringstatic final Stringprotected Stringprotected Stringstatic final Stringprotected TextProviderFactoryprotected UrlRendererprotected Stringprotected StringFields inherited from class org.apache.struts2.components.UIBean
accesskey, ATTR_FIELD_VALUE, ATTR_NAME_VALUE, ATTR_VALUE, cspNonceReader, cssClass, cssErrorClass, cssErrorStyle, cssStyle, defaultTemplateDir, defaultUITheme, disabled, dynamicAttributes, errorPosition, html5ConstraintsEnabled, htmlConstraintProvider, id, javascriptTooltip, key, label, labelPosition, labelSeparator, name, onblur, onchange, onclick, ondblclick, onfocus, onkeydown, onkeypress, onkeyup, onmousedown, onmousemove, onmouseout, onmouseover, onmouseup, onselect, request, requiredLabel, requiredPosition, response, tabindex, template, templateDir, templateEngineManager, templateSuffix, theme, title, tooltip, tooltipConfig, tooltipCssClass, tooltipDelay, tooltipIconPath, uiStaticContentPath, uiThemeExpansionToken, valueFields inherited from class org.apache.struts2.components.Component
actionMapper, attributes, COMPONENT_STACK, devMode, escapeHtmlBody, performClearTagStateForTagPoolingServers, stack, standardAttributesMap, throwExceptionOnELFailure -
Constructor Summary
ConstructorsConstructorDescriptionForm(ValueStack stack, jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response) -
Method Summary
Modifier and TypeMethodDescriptionprotected voidevaluateClientSideJsEnablement(String actionName, String namespace, String actionMethod) Deprecated, for removal: This API element is subject to removal in a future version.since 7.4.0, for removal in 8.0.0.protected voidprotected booleanprotected StringA contract that requires each concrete UI Tag to specify which template should be used as a default.getFieldValidators(String name) Returns the validators declared for a single field, resolving the action's validator list at most once per form render.protected intGet a incrementing sequence unique to thisFormcomponent.getValidatedObject(String name) The object a field's validators run against: the visited object for a field reached through avisitorvalidator, otherwise null — the caller then uses the action, as validation does.getValidators(String name) Deprecated, for removal: This API element is subject to removal in a future version.since 7.4.0, for removal in 8.0.0.protected ClassgetVisitorReturnType(Class actionClass, String visitorFieldName) Return type of visited object.protected voidpopulateComponentHtmlId(Form form) Form component determine the its HTML element id as follows:- if an 'id' attribute is specified. if an 'action' attribute is specified, it will be used as the id.voidsetAcceptcharset(String acceptcharset) voidvoidvoidsetConfiguration(Configuration configuration) voidsetEnctype(String enctype) voidsetFocusElement(String focusElement) voidsetIncludeContext(boolean includeContext) voidvoidsetNamespace(String namespace) voidsetObjectFactory(ObjectFactory objectFactory) voidsetOnreset(String onreset) voidsetOnsubmit(String onsubmit) voidsetPortletMode(String portletMode) voidvoidsetTextProviderFactory(TextProviderFactory textProviderFactory) voidsetUrlRenderer(UrlRenderer urlRenderer) voidsetValidate(String validate) Deprecated, for removal: This API element is subject to removal in a future version.since 7.4.0, for removal in 8.0.0.voidsetWindowState(String windowState) Methods inherited from class org.apache.struts2.components.ClosingUIBean
setOpenTemplate, startMethods inherited from class org.apache.struts2.components.UIBean
addConstraintAttributes, addFormParameter, applyValueParameter, buildTemplateName, copyAttributes, enableAncestorFormCustomOnsubmit, end, ensureAttributeSafelyNotEscaped, escape, evaluateParams, getControlType, getId, getTemplate, getTemplateDir, getTheme, getTooltipConfig, getValueClassType, lazyEvaluation, mergeTemplate, setAccesskey, setCspNonceReader, setCssClass, setCssErrorClass, setCssErrorStyle, setCssStyle, setDefaultTemplateDir, setDefaultUITheme, setDisabled, setDynamicAttributes, setErrorPosition, setHtml5ConstraintsEnabled, setHtmlConstraintProvider, setId, setJavascriptTooltip, setKey, setLabel, setLabelPosition, setLabelSeparator, setName, setOnblur, setOnchange, setOnclick, setOndblclick, setOnfocus, setOnkeydown, setOnkeypress, setOnkeyup, setOnmousedown, setOnmousemove, setOnmouseout, setOnmouseover, setOnmouseup, setOnselect, setRequiredLabel, setRequiredPosition, setStaticContentPath, setStyle, setTabindex, setTemplate, setTemplateDir, setTemplateEngineManager, setTheme, setTitle, setTooltip, setTooltipConfig, setTooltipCssClass, setTooltipDelay, setTooltipIconPath, setUIThemeExpansionToken, setValueMethods inherited from class org.apache.struts2.components.Component
addAllAttributes, addParameter, clearStandardAttributesMap, completeExpression, determineActionURL, determineNamespace, end, escapeHtmlBody, fieldError, findAncestor, findString, findString, findValue, findValue, findValue, getAttributes, getComponentStack, getNamespace, getPerformClearTagStateForTagPoolingServers, getStack, getStandardAttributes, isAcceptableExpression, isValidTagAttribute, popComponentStack, setActionMapper, setDevMode, setEscapeHtmlBody, setNotExcludedAcceptedPatterns, setPerformClearTagStateForTagPoolingServers, setThrowExceptionsOnELFailure, setUrlHelper, stripExpression, toString, usesBody
-
Field Details
-
OPEN_TEMPLATE
- See Also:
-
TEMPLATE
- See Also:
-
onsubmit
-
onreset
-
action
-
target
-
enctype
-
method
-
namespace
-
validate
-
portletMode
-
windowState
-
acceptcharset
-
includeContext
protected boolean includeContext -
focusElement
-
configuration
-
objectFactory
-
urlRenderer
-
actionValidatorManager
-
textProviderFactory
-
-
Constructor Details
-
Form
public Form(ValueStack stack, jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response)
-
-
Method Details
-
evaluateNameValue
protected boolean evaluateNameValue()- Overrides:
evaluateNameValuein classUIBean
-
getDefaultOpenTemplate
- Specified by:
getDefaultOpenTemplatein classClosingUIBean
-
getDefaultTemplate
Description copied from class:UIBeanA 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:
getDefaultTemplatein classUIBean- Returns:
- The name of the template to be used as the default.
-
setConfiguration
-
setObjectFactory
-
setUrlRenderer
-
setActionValidatorManager
-
setTextProviderFactory
-
evaluateExtraParams
protected void evaluateExtraParams()- Overrides:
evaluateExtraParamsin classUIBean
-
populateComponentHtmlId
Form component determine the its HTML element id as follows:-- if an 'id' attribute is specified.
- if an 'action' attribute is specified, it will be used as the id.
- Overrides:
populateComponentHtmlIdin classUIBean- Parameters:
form- enclosing form tag
-
evaluateClientSideJsEnablement
@Deprecated(since="7.4.0", forRemoval=true) protected void evaluateClientSideJsEnablement(String actionName, String namespace, String actionMethod) Deprecated, for removal: This API element is subject to removal in a future version.since 7.4.0, for removal in 8.0.0. The generated client-side validator only ever covered fields rendered by a nested Struts tag (WW-2975). Use thehtml5theme withstruts.ui.html5.constraints=true, which derives native HTML5 constraint attributes per field instead.Evaluate client side JavaScript Enablement.- Parameters:
actionName- the actioName to check fornamespace- the namespace to check foractionMethod- the method to ckeck for
-
getValidators
Deprecated, for removal: This API element is subject to removal in a future version.since 7.4.0, for removal in 8.0.0. UsegetFieldValidators(String), which is generically typed and resolves the action's validators once per form rather than per field.Looks up the validators for a field, for the deprecated client-side JavaScript validator.- Parameters:
name- the field name to look up- Returns:
- the validators applying to the field, never null
-
getFieldValidators
Returns the validators declared for a single field, resolving the action's validator list at most once per form render.- Since:
- 7.4.0
-
getValidatedObject
The object a field's validators run against: the visited object for a field reached through avisitorvalidator, otherwise null — the caller then uses the action, as validation does. Resolved bygetFieldValidators(String), which must run first.- Since:
- 7.4.0
-
getVisitorReturnType
Return type of visited object.- Parameters:
actionClass- action classvisitorFieldName- field name- Returns:
- type of visited object
-
getSequence
protected int getSequence()Get a incrementing sequence unique to thisFormcomponent. It is used byFormcomponent's child that might need a sequence to make them unique.- Returns:
- int
-
setOnsubmit
-
setOnreset
-
setAction
-
setTarget
-
setEnctype
-
setMethod
-
setNamespace
-
setValidate
Deprecated, for removal: This API element is subject to removal in a future version.since 7.4.0, for removal in 8.0.0. The generated client-side validator only ever covered fields rendered by a nested Struts tag (WW-2975). Use thehtml5theme withstruts.ui.html5.constraints=trueinstead. -
setPortletMode
-
setWindowState
-
setAcceptcharset
-
setFocusElement
-
setIncludeContext
public void setIncludeContext(boolean includeContext)
-