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??
Community moderators have prevented the ability to post new answers.
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
I think that did it. Thanks!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.