Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Bamboo Source - Proper Way To Get Multiple Checkbox Values After Extending BambooActionSupport

Adam Myatt
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 17, 2012

I'm doing some custom code work with Bamboo. I have a class that extends BambooActionSupport and have it set as an action that for input or execute it routes page execution from teh FTL template in the UI to the class :

@Override
public String doInput() throws Exception {

// load form field values here to display in UI

return INPUT;
}

@Override
public String doExecute() throws Exception {

// process changes submitted from UI

return SUCCESS;
}

In my UI template I have multiple checkboxes that all have the same value for the NAME attribute such as :

@ww.checkbox">[@ww.checkbox toggle='true' name='group' id='group_${group.id}' fieldValue="${group.id}" /]

@ww.checkbox">[@ww.checkbox toggle='true' name='group' id='group_${group.id}' fieldValue="${group.id}" /]

@ww.checkbox">[@ww.checkbox toggle='true' name='group' id='group_${group.id}' fieldValue="${group.id}" /]

From example I have seen it seems to get/set the form values you use standard bean setters and getters. I thought in the original class I stubbed out above that extends BambooActionSupport that to get the values from those checkboxes I could define :

private String[] group;

public void setGroup(String[] group) {
this.group= group;
}

public void setSendNotify(String[] group) {
this.group= group;
}

This seems to work fine for a single unique checkbox field but trying to use String[] getters and setters for a multiple value checkbox that shares the same NAME attribute it doesn't work and the value passed in is null.

Is there a correct way to handle multi-value checkboxes properly??

2 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

1 vote
Answer accepted
bmccoy
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
June 17, 2012

Hi Adam,

It looks like because you are using individual checkbox macros, it thinks they are single checkboxes, so is actually expecting "true" to be returned from getGroup() to mean that its checked (rather than a list of values). So you could either switch to using the checkbox list, or, put put your own logic in for the checked.

The checkbox list that should work:

[@ww.checkboxlist  name='group' label='Group' list=groupRow listKey='id' listValue='id'/]

Example code for your own checked logic:

[#assign itemChecked = group.contains(groupRow.id)/]
                    [@ww.checkbox toggle='true' name='group' id='group_${groupRow.id}' fieldValue="${groupRow.id}" checked=itemChecked /]

Cheers,

Brydie

Adam Myatt
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 18, 2012

I think that did it. Thanks!

0 votes
bmccoy
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
June 17, 2012

Hi Adam,

What you are doing looks correct. The only difference is we tend to use Collections rather than Arrays for the values that come back.

The other thing to note, is for single field checkboxes, I believe that the method will always get called, with true or false regardless of whether it was set. But for multivalue checkboxes, you should get a list of all the selected checkboxes. So you might be getting null if you haven't selected anything? This also means that you might need to do some magic to determine when things are unchecked depending on your use case.

Also, completely unrelated to your problem, but there is a checkboxlist macro which you might find useful for displaying multi-value checkbox lists e.g.

[@ww.checkboxlist  name='group' label='Group' list=groups listKey='id' listValue='id'/]

Cheers,

Brydie

Adam Myatt
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 17, 2012

I switched the String[] to Collection<String> and that seems to work better.

The second problem is that when doExecute succeeds and the UI redirects back to the webpage with the multi-checkboxes they are not re-populating to display the previously selected values.

Essentially when the UI page loads there are a dozen checkboxes initially blank, if the user selects one or more of them then submits the form the selected values get saved into Bandanamanager and then the original UI page displays again with the selected checkboxes set.

Right now the Ui page iterates through a list and displays 4 checkboxes using :

[#list groupList as groupRow]

@ww.checkbox">[@ww.checkbox toggle='true' name='group' id='group_${groupRow.id}' fieldValue="${groupRow.id}" /]

[/#list]

When the Ui page first loads to display those values from the list it seems to call the getter "Collection<String> getGroup()" 4 times, one for each of the checkboxs where the 'name' attribute is 'group'.

I have obviously been staring at this far too long since I'm sure I'm going about this all wrong. Any ideas?

TAGS
AUG Leaders

Atlassian Community Events