Class SelectTag

java.lang.Object
org.javalite.activeweb.freemarker.FreeMarkerTag
org.javalite.activeweb.freemarker.SelectTag
All Implemented Interfaces:
freemarker.template.TemplateDirectiveModel, freemarker.template.TemplateModel, RequestAccess

public class SelectTag extends FreeMarkerTag
Select tag is to generate the <select> HTML tag based on data passed in dynamically into a view.

Parameters:

  • list - this is a mandatory parameter, and it needs to be type of java.util.List filled with instances of SelectOption
In addition to the collection, you can also add body to the tag. For instance, if you write the tag like this:
 <@select list=books>
     <option value="3">A Tale of Two Cities</option>
   </@>
 
And pass this data from controller:
     view("books", list(new SelectOption(1, "The Hitchhiker's Guide to the Galaxy"), new SelectOption(2, "All Quiet on Western Front", true)));
 
then the output from the tag will be:
 <select>
       <option value="3">A Tale of Two Cities</option>
       <option value="1">The Hitchhiker's Guide to the Galaxy</option>
       <option value="2" selected="true">All Quiet on Western Front</option>
 </select>
Which means that the generated code is appended to hand-written body.

Adding HTML5-style attributes

Use a special attribute "data", whose value will be added to the resulting tag verbatim.
 <select data="data-greeting='hola' data-bye='astalavista'"  >
   ...
 </select>
Author:
Igor Polevoy: 4/12/12 1:13 PM
  • Constructor Details

    • SelectTag

      public SelectTag()
  • 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
      Parameters:
      params - this is a list of parameters as provided to tag in HTML.
      body - body of tag
      writer - writer to write output to.
      Throws:
      Exception - if any