Class FormTag
java.lang.Object
org.javalite.activeweb.freemarker.FreeMarkerTag
org.javalite.activeweb.freemarker.FormTag
- All Implemented Interfaces:
freemarker.template.TemplateDirectiveModel
,freemarker.template.TemplateModel
,RequestAccess
This is a FreeMarker directive which is registered as
<@form... />
tag.
This tag generates an HTML form tag and has functionality specific for ActiveWeb.
Like any other ActiveWeb tag, it has ability to pass through any non - ActiveWeb attributes. This means that if you
specify any attribute that is not mentioned here, it will be passed through as a regular HTML attribute.
Attributes:
- controller - name of a controller to post this form to. Optional. If this attribute is not provided, the tag will find a current controller in context which was used to generate a data for the current view and uses it. It makes it convenient to write many views for the same controller.
- action - name of an action to post this form to.This is different from regular HTML form@action attribute, as controller, action and id attributes will be used to form an appropriate HTML form action value. Optional.
- id - value of URI "id". Used as URI "id" in forming an HTML Form
action attribute, such as:
<form action="controller/action/id"
. Do not confuse with HTML element ID. Optional. - html_id - value of HTML Form element ID, as in
<form id="123..."
. Optoinal. - method - this is an HTTP method. Allowed values: GET (default), POST, PUT, DELETE. In case, the values are "put" or "delete", additional hidden input names "_method" will be generated, and the actual HTML method will be set to "post". This workaround is necessary because browsers still do not support PUT and DELETE. Optional.
RESTful
for more information.
Examples (given that the current context is "simple_context"):
Simple form
code:<@form controller="simple" action="index" method="get"/>will generate this HMTL:
<form action="/simple_context/simple/index" method="get"/>
POST form with ID
code:<@form controller="simple" action="index" id="123" method="post" html_id="formA"/>will generate:
<form action="/simple_context/simple/index/123" method="post" id="formA"/>
Put form
code:<@form controller="simple" action="index" method="put"> <input type="hidden" name="blah"> </@form>will generate this HMTL:
<form action="/simple_context/simple/index" method="post"> <input type='hidden' name='_method' value='put' /> <input type="hidden" name="blah"> </form>
Put form for RESTful controller
code:<@form controller="photos" id="x123" method="put" html_id="formA"> <input type="hidden" name="blah"> </@form>will generate:
<form action="/simple_context/photos/x123" method="post" id="formA"> <input type='hidden' name='_method' value='put' /> <input type="hidden" name="blah"> </form>
Adding HTML5-style attributes
Use a special attribute "data", whose value will be added to the resulting tag verbatim.<@form data="data-greeting='hola' data-bye='astalavista'" ... >
- Author:
- Igor Polevoy
-
Field Summary
Fields inherited from interface org.javalite.activeweb.RequestAccess
LOGGER
Fields inherited from interface freemarker.template.TemplateModel
NOTHING
-
Constructor Summary
-
Method Summary
Methods inherited from class org.javalite.activeweb.freemarker.FreeMarkerTag
execute, get, getAllVariables, getContextPath, getUnwrapped, getUnwrapped, logger, overrideContext, process, session, sessionObject, validateParamsPresence
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.javalite.activeweb.RequestAccess
appContext, context, cookie, cookies, cookieValue, exists, format, getId, getLocale, getRequestHost, getRequestPort, getRequestProperties, getRequestProtocol, getRoute, header, headers, host, ipAddress, ipForwardedFor, isDelete, isGet, isHead, isMethod, isMultipartContent, isPost, isPut, isXhr, locale, method, param, param, params, params, params, params1st, params1st, path, port, protocol, queryString, remoteAddress, remoteHost, requestHas, servletPath, session, session, uri, url, userAgent, xhr
-
Constructor Details
-
FormTag
public FormTag()
-
-
Method Details
-
render
Description copied from class:FreeMarkerTag
Implement this method ina concrete subclass.- Specified by:
render
in classFreeMarkerTag
- Parameters:
params
- this is a list of parameters as provided to tag in HTML.body
- body of tagwriter
- writer to write output to.- Throws:
Exception
- if any
-