tags:

views:

36

answers:

1

I need to do the filter in the datatable.

I have two dropdown and first is just static values..like filter by name,dob,age.Based on that open second dropdown and do the filter display the values.

<ice:selectOneMenu size="12" onchange="this.form.submit()"
                            partialSubmit="true" id="filterByPastDue"
                            valueChangeListener="#{details.filterByListener}">

<f:selectItem itemLabel="None" itemValue="1" />
<f:selectItem itemLabel="Name" itemValue="2" />
<f:selectItem itemLabel="Age" itemValue="3" />
     <f:selectItem itemLabel="DOB" itemValue="4" />


<ice:selectOneMenu                              binding="#{person.selectFilterItems}" size="12"                             id="OpenFilterMenu" rendered="false">

In my mangebean have logic to get values in second drop down values.

public void filterByListener(ValueChangeEvent valueChangeEvent) {
    int filterBy = Integer
            .parseInt((String) valueChangeEvent.getNewValue());

    switch (filterBy) {

    case 1: {
        filterItems = null;
        filterItems = new HashSet<SelectItem>();
        filterOptions = null;
        filterOptions = new HashSet<String>();
        outputTextFor = false;
        selectFilterItems.setRendered(false);

        break;
    }
    case 2: {
        // clearing arraylist
        filterItems = null;
        filterItems = new HashSet<SelectItem>();
        filterOptions = null;
        filterOptions = new HashSet<String>();

        // loading arrayList
        for (int i = 0; i < person.size(); i++) {
            filterOptions.add(person.get(i).getName()
                    .toString());
        }

        Iterator it = filterOptions.iterator();

        while (it.hasNext()) {
            String s = (String) it.next();
            filterItems.add(new SelectItem(s, s));

        }
        // rendering components
        outputTextFor = true;
        selectFilterItems.setRendered(true);

        break;
    }
    case 3: {
        // clearing arraylist
        filterItems = null;
        filterItems = new HashSet<SelectItem>();
        filterOptions = null;
        filterOptions = new HashSet<String>();
        // loading arrayList
        for (int i = 0; i < person.size(); i++) {
            filterOptions.add(person.get(i).getAge());
        }
        Iterator it = filterOptions.iterator();

        while (it.hasNext()) {
            String s = (String) it.next();
            filterItems.add(new SelectItem(s, s));

        }
        // rendering components
        outputTextFor = true;
        selectFilterItems.setRendered(true);

        break;
    }
    case 4: {
        // clearing arraylist
        filterItems = null;
        filterItems = new HashSet<SelectItem>();
        filterOptions = null;
        filterOptions = new HashSet<String>();
        // loading arrayList

        for (int i = 0; i < person.size(); i++) {
            filterOptions.add(person.get(i).getDOB());
        }
        Iterator it = filterOptions.iterator();

        while (it.hasNext()) {
            String s = (String) it.next();
            filterItems.add(new SelectItem(s, s));
        }
        // rendering components
        outputTextFor = true;
        selectFilterItems.setRendered(true);

        break;
    }
            default: {
        // clearing arrayList
        filterItems = null;
        filterItems = new HashSet<SelectItem>();
        filterOptions = null;
        filterOptions = new HashSet<String>();
        outputTextFor = false;
        selectFilterItems.setRendered(false);

        break;
    }
    }

}

Now i got the second drop down values what in my datatable.

Now, how to get the filter values display in the datatable.I having person object and need to display the datatables which ever selected in the second drop down.

A: 

You need to preset the property associated the value attribute of the h:dataTable with the desired datamodel. You could do that in the action method of the submit button or valueChangeListener method of the second dropdown. E.g.

public void submit() {
    this.dataModel = getDataModelSomehow(filterBy, filterOption);
}
BalusC