Highlight and uncheck the box using the checkbox

I have two types of checkboxes. One of them is a simple flag, for example t:selectBooleanCheckbox, and the other is a dynamically generated list t:selectBooleanCheckbox. I want to manage this list with one checkbox. For instance. when it is selected or canceled, similar actions should be performed for the list.

+1
source share
1 answer

With JSF 1.x, there are two ways to achieve this.

  • Submit the form to the onclick server of this check box.

    <t:selectBooleanCheckbox value="#{bean.selectAll}" onclick="submit()" />
    

    And just follow the logic of selecting / deselecting all the checkboxes.

    public void submit() {
        for (CheckboxItem item : checkboxItems) {
            item.setSelected(selectAll);
        }
    }
    

    : . - , , . JSF, .

  • JavaScript, .

    <t:selectBooleanCheckbox value="#{bean.selectAll}" onclick="selectAll(this)" />
    

    function selectAll(checkbox) {
        var elements = checkbox.form.elements;
        for (var i = 0; i < elements.length; i++) {
            var element = elements[i];
            if (/checkboxId$/.test(element.id)) {
                element.checked = checkbox.checked;
            }
        }
    }
    

    , , , , checkboxId. HTML, . , , , .

, , " ", .

JSF 2.x , , <f:ajax> onclick.

+6

Source: https://habr.com/ru/post/1769730/


All Articles