org.loom.tags.core
Class FormTag

java.lang.Object
  extended by javax.servlet.jsp.tagext.SimpleTagSupport
      extended by org.loom.tags.AbstractTag
          extended by org.loom.tags.AbstractDecoratedTag
              extended by org.loom.tags.AbstractHtmlTag
                  extended by org.loom.tags.core.FormTag
All Implemented Interfaces:
javax.servlet.jsp.tagext.DynamicAttributes, javax.servlet.jsp.tagext.JspTag, javax.servlet.jsp.tagext.SimpleTag, Form, HtmlTag, LoomTag, ParameterContainer

@Tag(dynamicAttributes=true,
     bodyContent=SCRIPTLESS,
     example="<l:form action=\"Mortgages\" event=\"save\">\n    <l:inputHidden name=\"mortgage.id\"/>\n    <l:inputText name=\"mortgage.name\"/>\n    <l:inputCheckbox name=\"mortgage.starred\"/>\n    <l:inputSelect name=\"mortgage.country\" options=\"${action.countries}\" />\n    <l:inputFile name=\"mortgage.photo\"/>\n</l:form>")
public class FormTag
extends AbstractHtmlTag
implements ParameterContainer, Form

HTML form tag. This tag includes a target action and event that are not only used to generate the target URL but also dictates the validations that will be applied to the input fields.


Field Summary
static boolean DEFAULT_RENDER_LABEL
          should the form fields render a label by default, default true
static boolean DEFAULT_SEPARATE_ERRORS
          should the form fields render the error message as an HTML component by default, default false
 
Fields inherited from class org.loom.tags.AbstractDecoratedTag
decorator
 
Fields inherited from class org.loom.tags.AbstractTag
expressionLanguageProxy, loomServletRequestFactory, out, repository, request, response
 
Constructor Summary
FormTag()
           
 
Method Summary
 void addHiddenField(java.lang.String name, java.lang.Object value)
          Add a hidden field to this component.
 ParameterContainer addParameter(java.lang.String name, java.lang.Object value)
          Adds a parameter to the resulting url
protected  void calculateHiddenFields()
          Calculate all the hidden fields to add to this form instance
 java.lang.String calculateMethodOverride()
          When displaying the form tag, this method calculates the value of the OVERRIDE_METHOD parameter, for use with DELETE and PUT methods which are not supported by the browser.
 boolean doRenderLabel()
           
 boolean doRenderSeparateErrors()
           
 void doTagImpl()
          The method that must be implemented by the child class
protected  void endTag()
          Does the tag cleanup, if any.
 java.lang.String getMethod()
           
 ActionMapping getTargetAction()
           
 Event getTargetEvent()
           
 UrlBuilder getUrl()
           
protected  void initTag()
          Initializes the tag attributes
 boolean isDisabled()
           
 boolean isRenderAsText()
           
 void setAccept(java.lang.String accept)
           
 void setAcceptCharset(java.lang.String acceptCharset)
           
 void setAction(java.lang.String action)
          An Action instance or Class to get called when this form gets submitted.
 void setAutocomplete(java.lang.Boolean autocomplete)
           
 void setDisabled(boolean disable)
           
 void setEnctype(java.lang.String encType)
           
 void setEvent(java.lang.String event)
          The event that will be invoked when this form is submitted
 void setHash(java.lang.String hash)
          The hash of the url (the fragment after '#')
 void setHostname(java.lang.String serverName)
          The server name to use.
 void setMapping(java.lang.String mapping)
          The mapping as action.event.
 void setMethod(java.lang.String method)
           
 void setMultipart(boolean multipart)
          Sets this form to submit multipart data.
 void setPort(java.lang.Integer port)
          The port to use.
 void setRelative(boolean relative)
          true if the url is relative (do not render schema, server or port), false to render a full URL.
 void setRenderAsText(boolean readOnly)
           
 void setRenderLabel(java.lang.Boolean renderLabel)
           
 void setRequest(LoomServletRequest request)
           
 void setScheme(java.lang.String scheme)
          The scheme to use.
 void setSeparateErrors(java.lang.Boolean renderError)
           
 void setTarget(java.lang.String target)
           
 
Methods inherited from class org.loom.tags.AbstractHtmlTag
addCssClass, getAccesskey, getCssBuilder, getCssClass, getDir, getId, getLang, getName, getStyle, getTitle, getTranslatedTitle, identify, isCssProcessed, isIf, isTranslateTitle, printParentAttributes, renderTag, setAccesskey, setCssClass, setCssProcessed, setDir, setId, setIf, setLang, setName, setStyle, setTitle, setTranslateTitle
 
Methods inherited from class org.loom.tags.AbstractDecoratedTag
doTag, getDecorator, getDecoratorInstance, setDecorator
 
Methods inherited from class org.loom.tags.AbstractTag
createWriterWrapper, doBody, doBufferedBody, evaluateExpression, getActionProperty, getAncestorWithClass, getBufferedBody, getExtendedAttributes, getMessagesRepository, getPageContext, getRequest, getResponse, getScopedAttribute, getWriter, removeScopedAttribute, setDynamicAttribute, setExtendedAttribute, setJspContext, setResponse, setScopedAttribute, setWriter
 
Methods inherited from class javax.servlet.jsp.tagext.SimpleTagSupport
findAncestorWithClass, getJspBody, getJspContext, getParent, setJspBody, setParent
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.loom.tags.HtmlTag
addCssClass, getCssBuilder
 
Methods inherited from interface org.loom.tags.LoomTag
getExtendedAttributes, getRequest, getScopedAttribute, setExtendedAttribute, setScopedAttribute
 

Field Detail

DEFAULT_RENDER_LABEL

public static boolean DEFAULT_RENDER_LABEL
should the form fields render a label by default, default true


DEFAULT_SEPARATE_ERRORS

public static boolean DEFAULT_SEPARATE_ERRORS
should the form fields render the error message as an HTML component by default, default false

Constructor Detail

FormTag

public FormTag()
Method Detail

setRequest

public void setRequest(LoomServletRequest request)
Overrides:
setRequest in class AbstractTag

initTag

protected void initTag()
Description copied from class: AbstractTag
Initializes the tag attributes

Overrides:
initTag in class AbstractTag

endTag

protected void endTag()
Description copied from class: AbstractTag
Does the tag cleanup, if any.

Overrides:
endTag in class AbstractTag

doTagImpl

public void doTagImpl()
               throws javax.servlet.jsp.JspException,
                      java.io.IOException
Description copied from class: AbstractTag
The method that must be implemented by the child class

Specified by:
doTagImpl in class AbstractTag
Throws:
javax.servlet.jsp.JspException
java.io.IOException

calculateHiddenFields

protected void calculateHiddenFields()
Calculate all the hidden fields to add to this form instance


addHiddenField

public void addHiddenField(java.lang.String name,
                           java.lang.Object value)
Add a hidden field to this component. These fields will get appended at the end of the form.

Specified by:
addHiddenField in interface Form
Parameters:
name - the name of the input element
value - the value, its toString form will be used. If null, the entire element will be omitted.

calculateMethodOverride

public java.lang.String calculateMethodOverride()
When displaying the form tag, this method calculates the value of the OVERRIDE_METHOD parameter, for use with DELETE and PUT methods which are not supported by the browser. If this.method has not yet been initialized, assign a suitable value according to the event.

Returns:
the String to be added to the form as an input hidden, null if none
Throws:
java.lang.IllegalArgumentException - if a method has been specified that is not supported by the assigned event

setAccept

public void setAccept(java.lang.String accept)

setAcceptCharset

public void setAcceptCharset(java.lang.String acceptCharset)

setEnctype

public void setEnctype(java.lang.String encType)

setMethod

public void setMethod(java.lang.String method)

setTarget

public void setTarget(java.lang.String target)

setAction

@Attribute
public void setAction(java.lang.String action)
An Action instance or Class to get called when this form gets submitted.

Parameters:
action - the (unqualified or qualified) name of the action to use for this form

setEvent

@Attribute
public void setEvent(java.lang.String event)
The event that will be invoked when this form is submitted


setRelative

@Attribute
public void setRelative(boolean relative)
true if the url is relative (do not render schema, server or port), false to render a full URL. Default is true


setScheme

@Attribute
public void setScheme(java.lang.String scheme)
The scheme to use. If not specified, the current request scheme will be used.

Parameters:
scheme - the scheme to use. Examples are: "http", "https"

setHostname

@Attribute
public void setHostname(java.lang.String serverName)
The server name to use. If not specified, the current request.getServerName() value will be used.


setPort

@Attribute
public void setPort(java.lang.Integer port)
The port to use. If not specified, the current request port will be used.

Parameters:
port - the port to use. Examples are: 80, 443

setHash

@Attribute
public void setHash(java.lang.String hash)
The hash of the url (the fragment after '#')


setMapping

@Attribute
public void setMapping(java.lang.String mapping)
The mapping as action.event. This method is equivalent to setting action and event separately.


getTargetAction

public ActionMapping getTargetAction()
Returns:
the ActionMapping this form points to

getTargetEvent

public Event getTargetEvent()

setMultipart

public void setMultipart(boolean multipart)
Sets this form to submit multipart data. Required if the form is going to submit input type="file" fields

Parameters:
multipart - boolean to set multipart, false if not

doRenderLabel

public boolean doRenderLabel()
Returns:
if the renderLabel property has been set, return that; else, check the global configuration

doRenderSeparateErrors

public boolean doRenderSeparateErrors()
Returns:
if the renderError property has been set, return that; else, check the global configuration

setSeparateErrors

public void setSeparateErrors(java.lang.Boolean renderError)

setRenderLabel

public void setRenderLabel(java.lang.Boolean renderLabel)

isDisabled

public boolean isDisabled()

setDisabled

public void setDisabled(boolean disable)

isRenderAsText

public boolean isRenderAsText()

setRenderAsText

public void setRenderAsText(boolean readOnly)

setAutocomplete

public void setAutocomplete(java.lang.Boolean autocomplete)

getMethod

public java.lang.String getMethod()

addParameter

public ParameterContainer addParameter(java.lang.String name,
                                       java.lang.Object value)
Description copied from interface: ParameterContainer
Adds a parameter to the resulting url

Specified by:
addParameter in interface ParameterContainer
Parameters:
name - the name of the parameter
value - the value of the parameter
Returns:
the same instance of ParameterContainer, to allow nested calls.

getUrl

public UrlBuilder getUrl()
Specified by:
getUrl in interface Form
Returns:
the target url of this link