Class FormTag

All Implemented Interfaces:
freemarker.template.TemplateDirectiveModel, freemarker.template.TemplateModel, RequestAccess

public class FormTag extends FreeMarkerTag
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.


  • 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.
This tag also is REST-aware, and will generate appropriate formats for HTML Form tag action value depending if the controller is RESTful or not, see RESTful for more information.

Examples (given that the current context is "simple_context"):

Simple form

 <@form controller="simple" action="index" method="get"/>
will generate this HMTL:
 <form action="/simple_context/simple/index" method="get"/>

POST form with ID

 <@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

  <@form controller="simple" action="index" method="put">
       <input type="hidden" name="blah">
will generate this HMTL:
 <form action="/simple_context/simple/index" method="post">
       <input type='hidden' name='_method' value='put' />
       <input type="hidden" name="blah">

Put form for RESTful controller

<@form controller="photos"  id="x123" method="put" html_id="formA">
       <input type="hidden" name="blah">
will generate:
  <form action="/simple_context/photos/x123" method="post" id="formA">
       <input type='hidden' name='_method' value='put' />
       <input type="hidden" name="blah">

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'" ...  >
Igor Polevoy
  • Constructor Details

    • FormTag

      public FormTag()
  • Method Details

    • render

      protected void render(Map params, String body, Writer writer) throws Exception
      Description copied from class: FreeMarkerTag
      Implement this method ina concrete subclass.
      Specified by:
      render in class FreeMarkerTag
      params - this is a list of parameters as provided to tag in HTML.
      body - body of tag
      writer - writer to write output to.
      Exception - if any