Class FormTag
- All Implemented Interfaces:
javax.servlet.jsp.tagext.BodyTag
,javax.servlet.jsp.tagext.DynamicAttributes
,javax.servlet.jsp.tagext.IterationTag
,javax.servlet.jsp.tagext.JspTag
,javax.servlet.jsp.tagext.Tag
,javax.servlet.jsp.tagext.TryCatchFinally
,net.sourceforge.stripes.tag.ParameterizableTag
Form tag for use with the Stripes framework. Supports all of the HTML attributes applicable to the form tag, with one exception: due to JSP attribute naming restrictions accept-charset is specified as acceptcharset (but will be rendered correctly in the output HTML).
-
Field Summary
Fields inherited from class net.sourceforge.stripes.tag.StripesTagSupport
pageContext, parentTag
Fields inherited from interface javax.servlet.jsp.tagext.BodyTag
EVAL_BODY_BUFFERED, EVAL_BODY_TAG
Fields inherited from interface javax.servlet.jsp.tagext.IterationTag
EVAL_BODY_AGAIN
Fields inherited from interface javax.servlet.jsp.tagext.Tag
EVAL_BODY_INCLUDE, EVAL_PAGE, SKIP_BODY, SKIP_PAGE
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
addParameter
(String name, Object valueOrValues) Appends a parameter to the "action" attribute of the form tag.protected String
Builds the action attribute, including the context path and any parameters.int
Just returns SKIP_BODY so that the body is included only once.void
Rethrows the passed in throwable in all cases.int
doEndTag()
Writes things out in the following order: The form open tag Hidden fields for the form name and source page The buffered body content The form close tagvoid
Used to ensure that the form is always removed from the tag stack so that there is never any confusion about tag-parent hierarchies.void
No-op method.int
Does sanity checks and returns EVAL_BODY_BUFFERED.protected net.sourceforge.stripes.action.ActionBean
Fetches the ActionBean associated with the form if one is present.protected Class<? extends net.sourceforge.stripes.action.ActionBean>
Lazily looks up and returns the type of action bean the form will submit to.protected String
Get the URL binding for the form'sActionBean
from theActionResolver
.Corresponding getter for 'beanclass', will always return null.Gets the form encoding.getFocus()
Gets the name of the field that should receive focus when the form is rendered.Gets the HTTP method to use when the form is submitted.getName()
Gets the set of all field names for which fields have been referred within the form up until the point of calling this method.boolean
Gets the flag that indicates if this is a partial form.protected boolean
isWizard()
Returns true if the ActionBean this form posts to represents a Wizard action bean and false in all other situations.void
registerField
(net.sourceforge.stripes.tag.InputTagSupport tag) Used by nested tags to notify the form that a field with the specified name has been written to the form.void
void
setAcceptcharset
(String acceptCharset) void
Sets the action for the form.void
setBeanclass
(Object beanclass) Sets the 'action' attribute by inspecting the bean class provided and asking the current ActionResolver what the appropriate URL is.void
setEnctype
(String enctype) Sets the form encoding.void
Sets the name of the field that should receive focus when the form is rendered.protected void
setFocusOnFieldIfRequired
(net.sourceforge.stripes.tag.InputTagSupport tag) Checks to see if the field should receive focus either because it is the named field for receiving focus, because it is the first field in the form (and first field focus was specified), or because it is the first field in error.void
Sets the HTTP method to use when the form is submitted.void
void
setOnreset
(String onreset) void
setOnsubmit
(String onsubmit) void
setPartial
(boolean partial) Sets the flag that indicates if this is a partial form.void
protected void
writeFieldsPresentHiddenField
(javax.servlet.jsp.JspWriter out) In general writes out a hidden field notifying the server exactly what fields were present on the page.protected void
Writes out hidden fields for all fields that are present in the request but are not explicitly present in this form.Methods inherited from class net.sourceforge.stripes.tag.FormTag
getFieldsPresentValue, getSourcePageValue, writeHiddenTags, writeSourcePageHiddenField
Methods inherited from class net.sourceforge.stripes.tag.HtmlTagSupport
evaluateExpression, get, getAccesskey, getAttributes, getBodyContent, getBodyContentAsString, getCssClass, getDir, getId, getLang, getOnblur, getOnchange, getOnclick, getOndblclick, getOnfocus, getOnkeydown, getOnkeypress, getOnkeyup, getOnmousedown, getOnmousemove, getOnmouseout, getOnmouseover, getOnmouseup, getOnselect, getStyle, getTabindex, getTitle, release, set, setAccesskey, setBodyContent, setClass, setCssClass, setDir, setDynamicAttribute, setId, setLang, setOnblur, setOnchange, setOnclick, setOndblclick, setOnfocus, setOnkeydown, setOnkeypress, setOnkeyup, setOnmousedown, setOnmousemove, setOnmouseout, setOnmouseover, setOnmouseup, setOnselect, setStyle, setTabindex, setTitle, toString, writeAttributes, writeCloseTag, writeOpenTag, writeSingletonTag
Methods inherited from class net.sourceforge.stripes.tag.StripesTagSupport
getActionBeanType, getActionBeanUrl, getPageContext, getParent, getParentTag, getTagStack, popPageContextAttributes, pushPageContextAttributes, setPageContext, setParent
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface javax.servlet.jsp.tagext.BodyTag
setBodyContent
Methods inherited from interface javax.servlet.jsp.tagext.Tag
getParent, release, setPageContext, setParent
-
Constructor Details
-
FormTag
public FormTag()
-
-
Method Details
-
setAction
Sets the action for the form. If the form action begins with a slash, and does not already contain the context path, then the context path of the web application will get prepended to the action before it is set. In general actions should be specified as "absolute" paths within the web application, therefore allowing them to function correctly regardless of the address currently shown in the browser's address bar.- Overrides:
setAction
in classnet.sourceforge.stripes.tag.FormTag
- Parameters:
action
- the action path, relative to the root of the web application
-
getAction
- Overrides:
getAction
in classnet.sourceforge.stripes.tag.FormTag
-
getActionBeanUrlBinding
Get the URL binding for the form'sActionBean
from theActionResolver
.- Overrides:
getActionBeanUrlBinding
in classnet.sourceforge.stripes.tag.FormTag
-
getActionBeanClass
Lazily looks up and returns the type of action bean the form will submit to.- Overrides:
getActionBeanClass
in classnet.sourceforge.stripes.tag.FormTag
-
setBeanclass
public void setBeanclass(Object beanclass) throws net.sourceforge.stripes.exception.StripesJspException Sets the 'action' attribute by inspecting the bean class provided and asking the current ActionResolver what the appropriate URL is.- Overrides:
setBeanclass
in classnet.sourceforge.stripes.tag.FormTag
- Parameters:
beanclass
- the String FQN of the class, or a Class representing the class- Throws:
net.sourceforge.stripes.exception.StripesJspException
- if the URL cannot be determined for any reason, most likely because of a mis-spelled class name, or a class that's not an ActionBean
-
getBeanclass
Corresponding getter for 'beanclass', will always return null.- Overrides:
getBeanclass
in classnet.sourceforge.stripes.tag.FormTag
-
setFocus
Sets the name of the field that should receive focus when the form is rendered.- Overrides:
setFocus
in classnet.sourceforge.stripes.tag.FormTag
-
getFocus
Gets the name of the field that should receive focus when the form is rendered.- Overrides:
getFocus
in classnet.sourceforge.stripes.tag.FormTag
-
isPartial
public boolean isPartial()Gets the flag that indicates if this is a partial form.- Overrides:
isPartial
in classnet.sourceforge.stripes.tag.FormTag
-
setPartial
public void setPartial(boolean partial) Sets the flag that indicates if this is a partial form.- Overrides:
setPartial
in classnet.sourceforge.stripes.tag.FormTag
-
setEnctype
Sets the form encoding.- Overrides:
setEnctype
in classnet.sourceforge.stripes.tag.FormTag
-
getEnctype
Gets the form encoding.- Overrides:
getEnctype
in classnet.sourceforge.stripes.tag.FormTag
-
setMethod
Sets the HTTP method to use when the form is submitted.- Overrides:
setMethod
in classnet.sourceforge.stripes.tag.FormTag
-
getMethod
Gets the HTTP method to use when the form is submitted.- Overrides:
getMethod
in classnet.sourceforge.stripes.tag.FormTag
-
setAccept
- Overrides:
setAccept
in classnet.sourceforge.stripes.tag.FormTag
-
getAccept
- Overrides:
getAccept
in classnet.sourceforge.stripes.tag.FormTag
-
setAcceptcharset
- Overrides:
setAcceptcharset
in classnet.sourceforge.stripes.tag.FormTag
-
getAcceptcharset
- Overrides:
getAcceptcharset
in classnet.sourceforge.stripes.tag.FormTag
-
setName
- Overrides:
setName
in classnet.sourceforge.stripes.tag.FormTag
-
getName
- Overrides:
getName
in classnet.sourceforge.stripes.tag.FormTag
-
setTarget
- Overrides:
setTarget
in classnet.sourceforge.stripes.tag.FormTag
-
getTarget
- Overrides:
getTarget
in classnet.sourceforge.stripes.tag.FormTag
-
setOnreset
- Overrides:
setOnreset
in classnet.sourceforge.stripes.tag.FormTag
-
getOnreset
- Overrides:
getOnreset
in classnet.sourceforge.stripes.tag.FormTag
-
setOnsubmit
- Overrides:
setOnsubmit
in classnet.sourceforge.stripes.tag.FormTag
-
getOnsubmit
- Overrides:
getOnsubmit
in classnet.sourceforge.stripes.tag.FormTag
-
doStartTag
public int doStartTag() throws javax.servlet.jsp.JspExceptionDoes sanity checks and returns EVAL_BODY_BUFFERED. Everything else of interest happens in doEndTag.- Specified by:
doStartTag
in interfacejavax.servlet.jsp.tagext.Tag
- Overrides:
doStartTag
in classnet.sourceforge.stripes.tag.FormTag
- Throws:
javax.servlet.jsp.JspException
-
doInitBody
public void doInitBody() throws javax.servlet.jsp.JspExceptionNo-op method.- Specified by:
doInitBody
in interfacejavax.servlet.jsp.tagext.BodyTag
- Overrides:
doInitBody
in classnet.sourceforge.stripes.tag.FormTag
- Throws:
javax.servlet.jsp.JspException
-
doAfterBody
public int doAfterBody() throws javax.servlet.jsp.JspExceptionJust returns SKIP_BODY so that the body is included only once.- Specified by:
doAfterBody
in interfacejavax.servlet.jsp.tagext.IterationTag
- Overrides:
doAfterBody
in classnet.sourceforge.stripes.tag.FormTag
- Throws:
javax.servlet.jsp.JspException
-
doEndTag
public int doEndTag() throws javax.servlet.jsp.JspExceptionWrites things out in the following order:- The form open tag
- Hidden fields for the form name and source page
- The buffered body content
- The form close tag
All of this is done in doEndTag to allow form elements to modify the form tag itself if necessary. A prime example of this is the InputFileTag, which needs to ensure that the form method is GET and the enctype is correct.
- Specified by:
doEndTag
in interfacejavax.servlet.jsp.tagext.Tag
- Overrides:
doEndTag
in classnet.sourceforge.stripes.tag.FormTag
- Throws:
javax.servlet.jsp.JspException
-
doCatch
Rethrows the passed in throwable in all cases.- Specified by:
doCatch
in interfacejavax.servlet.jsp.tagext.TryCatchFinally
- Overrides:
doCatch
in classnet.sourceforge.stripes.tag.FormTag
- Throws:
Throwable
-
doFinally
public void doFinally()Used to ensure that the form is always removed from the tag stack so that there is never any confusion about tag-parent hierarchies.- Specified by:
doFinally
in interfacejavax.servlet.jsp.tagext.TryCatchFinally
- Overrides:
doFinally
in classnet.sourceforge.stripes.tag.FormTag
-
writeFieldsPresentHiddenField
In general writes out a hidden field notifying the server exactly what fields were present on the page. Exact behaviour depends upon whether or not the current form is a wizard or not. When the current form is not a wizard this method examines the form tag to determine what fields present in the form might not get submitted to the server (e.g. checkboxes, selects), writes out a hidden field that contains the names of all those fields so that we can detect non-submission when the request comes back.
In the case of a wizard form the value output is the full list of all fields that were present on the page. This is done because the list is used to drive required field validation knowing that in a wizard required fields may be spread across several pages.
In both cases the value is encrypted to stop the user maliciously spoofing the value.
- Overrides:
writeFieldsPresentHiddenField
in classnet.sourceforge.stripes.tag.FormTag
- Parameters:
out
- the output writer into which the hidden tag should be written- Throws:
IOException
- if the writer throws one
-
getActionBean
protected net.sourceforge.stripes.action.ActionBean getActionBean()Fetches the ActionBean associated with the form if one is present. An ActionBean will not be created (and hence not present) by default. An ActionBean will only be present if the current request got bound to the same ActionBean as the current form uses. E.g. if we are re-showing the page as the result of an error, or the same ActionBean is used for a "pre-Action" and the "post-action".- Overrides:
getActionBean
in classnet.sourceforge.stripes.tag.FormTag
- Returns:
- ActionBean the ActionBean bound to the form if there is one
-
isWizard
protected boolean isWizard()Returns true if the ActionBean this form posts to represents a Wizard action bean and false in all other situations. If the form cannot determine the ActionBean being posted to for any reason it will return false.- Overrides:
isWizard
in classnet.sourceforge.stripes.tag.FormTag
-
writeWizardFields
protected void writeWizardFields() throws javax.servlet.jsp.JspExceptionWrites out hidden fields for all fields that are present in the request but are not explicitly present in this form. Excludes any fields that have special meaning to Stripes and are not really application data. Uses the stripes:wizard-fields tag to do the grunt work.- Overrides:
writeWizardFields
in classnet.sourceforge.stripes.tag.FormTag
- Throws:
javax.servlet.jsp.JspException
-
registerField
public void registerField(net.sourceforge.stripes.tag.InputTagSupport tag) Used by nested tags to notify the form that a field with the specified name has been written to the form.- Overrides:
registerField
in classnet.sourceforge.stripes.tag.FormTag
- Parameters:
tag
- the input field tag being registered
-
setFocusOnFieldIfRequired
protected void setFocusOnFieldIfRequired(net.sourceforge.stripes.tag.InputTagSupport tag) Checks to see if the field should receive focus either because it is the named field for receiving focus, because it is the first field in the form (and first field focus was specified), or because it is the first field in error.- Overrides:
setFocusOnFieldIfRequired
in classnet.sourceforge.stripes.tag.FormTag
- Parameters:
tag
- the input tag being registered with the form
-
getRegisteredFields
Gets the set of all field names for which fields have been referred within the form up until the point of calling this method. If this is called during doEndTag it will contain all field names, if it is called during the body of the tag it will only contain the input elements which have been processed up until that point.- Overrides:
getRegisteredFields
in classnet.sourceforge.stripes.tag.FormTag
- Returns:
- Set
- the set of field names seen so far
-
addParameter
Appends a parameter to the "action" attribute of the form tag. For clean URLs the value will be embedded in the URL if possible. Otherwise, it will be added to the query string.- Specified by:
addParameter
in interfacenet.sourceforge.stripes.tag.ParameterizableTag
- Overrides:
addParameter
in classnet.sourceforge.stripes.tag.FormTag
- Parameters:
name
- the parameter namevalueOrValues
- the parameter value(s)- See Also:
-
ParameterizableTag.addParameter(String, Object)
-
buildAction
Builds the action attribute, including the context path and any parameters.- Overrides:
buildAction
in classnet.sourceforge.stripes.tag.FormTag
- Returns:
- the action attribute
-