/** * */ package pt.ist.renderers.extensions.controllers; import java.util.ArrayList; import java.util.List; import pt.ist.renderers.components.HtmlCheckBox; import pt.ist.renderers.components.HtmlMultipleValueComponent; import pt.ist.renderers.components.controllers.HtmlController; import pt.ist.renderers.components.state.IViewState; public class CopyCheckBoxValuesController extends HtmlController { private List checkboxes; private boolean copyTrueValues; public CopyCheckBoxValuesController() { super(); this.checkboxes = new ArrayList(); this.copyTrueValues = true; } public CopyCheckBoxValuesController(final boolean copyTrueValues) { this(); this.copyTrueValues = copyTrueValues; } public void addCheckBox(HtmlCheckBox checkBox) { this.checkboxes.add(checkBox); } @Override public void execute(IViewState viewState) { HtmlMultipleValueComponent component = (HtmlMultipleValueComponent) getControlledComponent(); List values = new ArrayList(); for (HtmlCheckBox checkBox : this.checkboxes) { if (checkBox.isChecked() == copyTrueValues) { values.add(checkBox.getValue()); } } component.setValues(values.toArray(new String[0])); } }