In my VF page I have a series of inputCheckboxes that mimic the implementation of selectCheckboxes (i.e. they are one after the other and 'related' to each other). Now with selectCheckboxes on submit I can get the values associated with each checked checkbox and concatenate them into one comma separated string. However, since in this page each of these checkboxes needs to have a complicated event associated with them such as rendering different things and having other fields beside them/ under them, it makes it pretty impossible to use selectCheckboxes, hence the series of regular inputCheckboxes.

The problem is on submit is there an easier way to aggregate all of the ones selected true and concat them into one comma-seperated string without something like:

if (box1 == true)
 result = String.join('foo', ', ' );
if (box2 == true)
 result = String.join('bar', ', ' );

1 Answer 1


You could use a map but then you lose compile-time checking. So I would do something like this:

List<String> s = new List<String>();
if (box1) s.add('foo');
if (box2) s.add('bar');
String csv = String.join(s, ', ');
  • Ah, that looks great, much cleaner looking. I am still implementing it so I cant try it yet but I dont foresee any issues thanks! Jul 23, 2014 at 15:33

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .