Adding checkbox as a type

JIRA Documentation

Index

This page provides an example of how to extend the available types listed on the Configuring Plugins with Object Configurable Parameters reference page.

JIRA Source Note:

You must own a commercial license of JIRA to have access to JIRA's source code-- a necessary part of this modification.

In the Atlassian JIRA Source modify the following:

ObjectConfigurationTypes.java
public class ObjectConfigurationTypes
{
   public static final int CHECKBOX = 9;
      ...

   public static int getType(String typeStr)
   {
      ...

      else if (typeStr.toLowerCase().startsWith("checkbox"))
      {
          return CHECKBOX;
      }

      ...
   }

}

 

 

objectconfiguration_form.jsp
<webwork:elseIf test="objectConfiguration/fieldType(.)==9"><%-- CHECKBOX --%>
    <webwork:property value="." />
    <webwork:property value="paramValue(.)" />
    <ui:component name="." value="paramValue(.)" label="text(objectConfiguration/fieldName(.))" template="checkbox.jsp">
        <ui:param name="'description'"><webwork:text name="objectConfiguration/fieldDescription(.)" /></ui:param>
        <ui:param name="'fieldValue'"><webwork:property value="paramValue(.)" /></ui:param>
    </ui:component>
</webwork:elseIf>

 

 

Example Plugin Code

This example uses the Issue Creation Report example (com.atlassian.jira.plugin.report.example) provided in the JIRA Plugin Development Kit.

In your plugin source (e.g. a report plugin) add the following property:

atlassian-plugin.xml
<property>
   <key>checkbox</key>
   <name>report.issuecreation.checkbox</name>
   <description>report.issuecreation.checkbox.description</description>
   <type>checkbox</type>
   <default>true</default>  //If you would like the default to be checked
</property>

Generally, your atlassian-plugin.xml will refer to a properties file (e.g. issuecreation_report.properties) for configuration of field labels and descriptions. Add the following attributes:

issuecreation_report.properties
report.issuecreation.checkbox = CheckBox Label
report.issuecreation.checkbox.description = A simple checkbox for test purposes.

 

 

Modify your plugin java file to extract/work with the boolean checkbox value:

CreationReport.java
...

public String generateReportHtml(ProjectActionSupport action, Map params) throws Exception
{
        User remoteUser = action.getRemoteUser();
        I18nHelper i18nBean = new I18nBean(remoteUser);

        // Retrieve the project parameter
        Long projectId = ParameterUtils.getLongParam(params, "projectid");
        // Retrieve the start and end dates and the time interval specified by the user
        Date startDate = ParameterUtils.getDateParam(params, "startDate", i18nBean.getLocale());
        Date endDate = ParameterUtils.getDateParam(params, "endDate", i18nBean.getLocale());
        Long interval = ParameterUtils.getLongParam(params, "interval");
        boolean checkbox = (Boolean.valueOf(ParameterUtils.getStringParam(params, "checkbox"))).booleanValue();
     ...

        velocityParams.put("checkbox", new Boolean(checkbox));
 }
   ...

 

 

Labels:

Enter labels to add to this page:
Wait Image 
Looking for a label? Just start typing.
  1. Dec 20, 2006

    Matt Doar says:

    Great example\! The checkbox type has actually been added to later releases of J...

    Great example! The checkbox type has actually been added to later releases of Jira.

  2. Oct 29, 2007

    Aggelos T. Paraskevopoulos says:

    How about adding a "password" field type. JIRA Confluence Portlet could make use...

    How about adding a "password" field type. JIRA Confluence Portlet could make use of this.