Sunday, 28 September 2014

ADF - Mutually Exclusive Checkboxes in Table

This Blog explain about how to implement mutually exclusive checkboxes in ADF table


From property inspector set the valuechangelistener for the checkbox and set AutoSubmit "true"




Add the below method in value-change listener.

    public void checkboxValueChange(ValueChangeEvent valueChangeEvent) {

        String newValue = valueChangeEvent.getNewValue().toString();
        if (newValue.equalsIgnoreCase("true")) {
            toggleNewProgramCheckBoxes(valueChangeEvent, "EmployeesView1Iterator");
            JSFUtil.storeOnSession("firstSelection", "firstSelection");
        } else if (JSFUtil.getFromSession("firstSelection") != null &&
                   JSFUtil.getFromSession("firstSelection").toString().equalsIgnoreCase("firstSelection") &&
                   newValue.equalsIgnoreCase("false")) {
            toggleNewProgramCheckBoxes(valueChangeEvent, "EmployeesView1Iterator");
        }
        // Add event code here...
    }


    public void toggleCheckBoxesOnSelection(ValueChangeEvent valuechangeEvent,
                                           String iteratorName) {

        BindingContext bindingContext = BindingContext.getCurrent();
        DCBindingContainer dcBindings =
            (DCBindingContainer)bindingContext.getCurrentBindingsEntry();
        DCIteratorBinding iterator =
            dcBindings.findIteratorBinding(iteratorName);
        ViewObject vo = iterator.getViewObject();
        RowSetIterator rit = vo.createRowSetIterator(null);
        String currentFileId =
            JSFUtil.getFromPageFlowScope("currentSelectedEmpId").toString();

        while (rit.hasNext()) {
            Row row = rit.next();
            row.setAttribute("empSelect", false);
            if (row.getAttribute("EmployeeId").toString().equalsIgnoreCase(currentFileId)) {
                row.setAttribute("empSelect", true);
            }
        }
        rit.closeRowSetIterator();

        AdfFacesContext.getCurrentInstance().addPartialTarget(JSFUtil.findComponentInRoot("emptab"));
    }

Add af:setPropertyListener as the child of checkbox with below configuration.









No comments:

Post a Comment