Bamboo Freemarker/Webworks multiple select issue

I'm building a custom task with GUI in Bamboo using Atlassian SDK with Freemarker and Webworks. The single select works fine but multiple select does not return multiple values only single value. My FTL code looks like below. In my TaskConfigurator class the selectedBarList field is not returned only the interfaceBar paramter is retruned with single value.

@ww.select">[@ww.selectlabel="List of Bars" id="interfaceBar" name="interfaceBar"
list="barInterfaceList"
listKey="id"
listValue="name"
value="selectedBarList"
multiple="true"
size="3"
required="true"
/]

1 answer

0 vote

If you explicitly specify "value" attribute then ww.select will not receive value from Freemarker context. Here's your code fixed:

[@ww.select 
label="Framework Deploy Or Interface Deploy"
       id="deployType"   
       name="deployType"
       list="deployTypeList"
       listKey="id"
       listValue="name"
       multiple="false"
       size="3"
       required="true"
       onclick="myFunction()"
/]

<div id="interfaceDiv">
[@ww.select label="Countries"
       id="country"
       name="country"
       list="countryList"
       listKey="id"
       listValue="name"
       multiple="false"
       size="3"
       required="true"
       onclick="myFunction()"
       /]

[@ww.select 
label="List of Bars"
       id="interfaceBar"   
       name="interfaceBar"
       list="barInterfaceList"
       listKey="id"
       listValue="name"
       multiple="true"
       size="3"
       required="true"
/]
</div>

<div id="frameworkDiv">
[@ww.select 
label="List of Bars"
       id="frameworkBarId"   
       name="frameworkBarName"
       list="barFrameworkList"
       listKey="id"
       listValue="name"
       multiple="true"
       size="10"
       required="true"
/]
</div>

<script>
function myFunction()
{
  var deployType=document.getElementById("deployType");
  alert("deploytype = " + deployType.value);
  
  var interfaceDiv=document.getElementById("interfaceDiv");
  var frameworkDiv=document.getElementById("frameworkDiv");
  if (deployType.value=='1'){
  	interfaceDiv.style.visibility="hidden";
  	frameworkDiv.style.visibility="visible";
  }
  else{
  	interfaceDiv.style.visibility="visible";
  	frameworkDiv.style.visibility="hidden";
  }
}
</script>

and the Java part:
package helloworld1;

import com.atlassian.bamboo.collections.ActionParametersMap;
import com.atlassian.bamboo.task.AbstractTaskConfigurator;
import com.atlassian.bamboo.task.TaskDefinition;
import com.atlassian.bamboo.utils.error.ErrorCollection;
import com.google.common.base.Function;
import com.google.common.base.Joiner;
import com.google.common.base.Objects;
import com.google.common.base.Splitter;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Iterables;
import com.google.common.collect.Maps;
import com.opensymphony.xwork.TextProvider;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.List;
import java.util.Map;

public class ExampleTaskConfigurator extends AbstractTaskConfigurator
{
    private TextProvider textProvider;

    private static final String CFG_DEPLOY_TYPE = "deployType.id";
    private static final String CFG_COUNTRY = "country.id";
    private static final String CFG_INTERFACE = "interface.id";
    private static final String CFG_FRAMEWORK = "framework.id";

    private static final String UI_DEPLOY_TYPE = "deployType";
    private static final String UI_DEPLOY_TYPE_NAME = "deployType.name";
    private static final String UI_DEPLOY_TYPE_LIST = "deployTypeList";
    private static final String UI_COUNTRY = "country";
    private static final String UI_COUNTRY_NAME = "country.name";
    private static final String UI_COUNTRY_LIST = "countryList";
    private static final String UI_INTERFACE = "interfaceBar";
    private static final String UI_INTERFACE_LIST = "barInterfaceList";
    private static final String UI_FRAMEWORK = "frameworkBarName";
    private static final String UI_FRAMEWORK_LIST = "barFrameworkList";

    private static final List<Deploy> deployTypeList = ImmutableList.of(
            new Deploy("1", "Framework"),
            new Deploy("2", "Interface"),
            new Deploy("3", "Jake"),
            new Deploy("4", "Broker Hub")
    );
    private static final Map<String, Deploy> deployTypeMap = Maps.uniqueIndex(deployTypeList, new Function<Deploy, String>()
    {
        @Override
        public String apply(Deploy deploy)
        {
            return deploy.getId();
        }
    });

    private static final List<Country> countryList = ImmutableList.of(
            new Country("1", "South Africa"),
            new Country("2", "Tanzania"),
            new Country("3", "Namibia"),
            new Country("4", "Nigeria"),
            new Country("5", "Uganda")
    );
    private static final Map<String, Country> countryMap = Maps.uniqueIndex(countryList, new Function<Country, String>()
    {
        @Override
        public String apply(Country country)
        {
            return country.getId();
        }
    });

    private static final List<Bar> barFrameworkList = ImmutableList.of(
            new Bar("1", "Input"),
            new Bar("2", "Output"),
            new Bar("3", "Transformation"),
            new Bar("4", "Fte"),
            new Bar("5", "Logging")
    );
    private static final List<Bar> barInterfaceList = ImmutableList.of(
            new Bar("1", "fin2pas"),
            new Bar("2", "esb2esb"),
            new Bar("3", "esb2mdm"),
            new Bar("4", "sprw2abc"),
            new Bar("5", "abc2xyz")
    );

    @NotNull
    @Override
    public Map<String, String> generateTaskConfigMap(@NotNull final ActionParametersMap params, @Nullable final TaskDefinition previousTaskDefinition)
    {
        final Map<String, String> config = super.generateTaskConfigMap(params, previousTaskDefinition);
        
        config.put(CFG_DEPLOY_TYPE, params.getString(UI_DEPLOY_TYPE));
        config.put(CFG_COUNTRY, params.getString(UI_COUNTRY));
        // plugin developer is responsible for null-safe serializing all non-string properties into configuration map
        config.put(CFG_INTERFACE, arrayToString(params.getStringArray(UI_INTERFACE)));
        config.put(CFG_FRAMEWORK, arrayToString(params.getStringArray(UI_FRAMEWORK)));

        System.out.println("config in generateTaskConfigMap: after put" + config);

        return config;
    }

    @Override
    public void populateContextForCreate(@NotNull final Map<String, Object> context)
    {
        super.populateContextForCreate(context);

        context.put(UI_DEPLOY_TYPE_LIST, deployTypeList);
        context.put(UI_COUNTRY_LIST, countryList);
        context.put(UI_INTERFACE_LIST, barInterfaceList);
        context.put(UI_FRAMEWORK_LIST, barFrameworkList);
    }

    @Override
    public void populateContextForEdit(@NotNull final Map<String, Object> context, @NotNull final TaskDefinition taskDefinition)
    {
        super.populateContextForEdit(context, taskDefinition);

        System.out.println("Edit: taskDefinition.getConfiguration() " + taskDefinition.getConfiguration());

        // Populate the Lists
        context.put(UI_DEPLOY_TYPE_LIST, deployTypeList);
        context.put(UI_COUNTRY_LIST, countryList);
        context.put(UI_INTERFACE_LIST, barInterfaceList);
        context.put(UI_FRAMEWORK_LIST, barFrameworkList);

        // Preselect chosen entry
        context.put(UI_DEPLOY_TYPE, taskDefinition.getConfiguration().get(CFG_DEPLOY_TYPE));
        context.put(UI_COUNTRY, taskDefinition.getConfiguration().get(CFG_COUNTRY));
        // plugin developer is responsible for null-safe deserializing of all non-string properties from configuration map
        context.put(UI_INTERFACE, stringToArray(taskDefinition.getConfiguration().get(CFG_INTERFACE)));
        context.put(UI_FRAMEWORK, stringToArray(taskDefinition.getConfiguration().get(CFG_FRAMEWORK)));
    }

    @Override
    public void populateContextForView(@NotNull final Map<String, Object> context, @NotNull final TaskDefinition taskDefinition)
    {
        super.populateContextForView(context, taskDefinition);

        context.put(UI_DEPLOY_TYPE_NAME, deployTypeMap.get(taskDefinition.getConfiguration().get(CFG_DEPLOY_TYPE)));
        context.put(UI_COUNTRY_NAME, countryMap.get(taskDefinition.getConfiguration().get(CFG_COUNTRY)));
    }

    @Override
    public void validate(@NotNull final ActionParametersMap params, @NotNull final ErrorCollection errorCollection)
    {
        super.validate(params, errorCollection);

//        final String sayValue = params.getString("say");
//        if (StringUtils.isEmpty(sayValue))
//        {
//            errorCollection.addError("say", textProvider.getText("helloworld1.say.error"));
//        }
    }

    public void setTextProvider(final TextProvider textProvider)
    {
        this.textProvider = textProvider;
    }


    @NotNull
    private String arrayToString(@Nullable String[] input)
    {
        return Joiner.on(",").join(Objects.firstNonNull(input, new String[]{}));
    }

    @NotNull
    private String[] stringToArray(@Nullable String input)
    {
        return Iterables.toArray(Splitter.on(",").split(Objects.firstNonNull(input, "")), String.class);
    }
}


Can you help me with creation of a simple dropdown ? 

What are the steps needed if I want to create a simple dropdown and get the selected value, persist it. 

I cannot find any reference in documentation or anywhere. 

Please, That would be much helpful. 

Thanks.

Suggest an answer

Log in or Join to answer
Community showcase
Renan Battaglin
Published May 18, 2017 in Bamboo

FAQ: How to Upgrade Bamboo Server

Bamboo 5.9 will no longer be supported after June 12, 2017. What does this mean? As part of our End of Life policy, Atlassian supports major versions for two years after the first major iteratio...

1,096 views 0 5
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot