Primefaces datatable filter issue with retaining object values when filter returns no rows

319 views Asked by At

I am using primefaces(6.2) datatable, while using column filter I am observing a weird behavior, though all the columns (with outputText, inputText) retain the object value, columns with 'selectOneMenu', 'selectBooleanCheckbox' not retaining the object value and returning null, false. Issue occurring only while performing the filter and filer returns no rows, if the filter returns at least one row everything looks normal and all columns are behaving normally. please find below code snippet that I am using to troubleshoot, I really appreciate any inputs to resolve this issue.

XHTML

    <html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:h="http://xmlns.jcp.org/jsf/html"
    xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
    xmlns:f="http://xmlns.jcp.org/jsf/core"
    xmlns:p="http://primefaces.org/ui"
    xmlns:c="http://java.sun.com/jstl/core">
<h:body>

<h:form id="frmClientDetails">
                            <p:dataTable 
                                        value="#{myBean.lstContact}" var="varContact" 
                                        rowStyleClass="#{varContact.strRowCSS}">
                                <p:column width="180" headerText="Sal">
                                    <p:selectOneMenu value="#{varContact.strSalutation}">
                                    <f:selectItem itemLabel="--Select one--" itemValue=""></f:selectItem>
                                    <f:selectItem itemLabel="DR" itemValue="DR"></f:selectItem>
                                    <f:selectItem itemLabel="MISS" itemValue="MISS"></f:selectItem>
                                    <f:selectItem itemLabel="MRS" itemValue="MRS"></f:selectItem>
                                    <f:selectItem itemLabel="MR" itemValue="MR"></f:selectItem>
                                    <f:selectItem itemLabel="MS" itemValue="MS"></f:selectItem>
                                    </p:selectOneMenu>
                                </p:column>
                                <p:column width="200" filterBy="#{varContact.strFirstName}" headerText="First Name">
                                    <p:inputText maxlength="2000" value="#{varContact.strFirstName}"/>
                                </p:column>
                                
                               </p:dataTable>
 
                            </h:form>

        </h:body>
</html>

ManagedBean

import java.util.ArrayList;
import java.util.List;

import javax.annotation.PostConstruct;
import javax.inject.Named;
import org.springframework.context.annotation.Scope;
import com.model.Contact;
@Named("myBean")
@Scope("view")
public class MyBean extends BaseManagedBean {
    private List<Contact> lstContact;

    @PostConstruct
    public void init() {
        lstContact = new ArrayList<Contact>();
        Contact obj1 = new Contact();
        obj1.setStrSalutation("MR");
        obj1.setStrFirstName("AAA");

        Contact obj2 = new Contact();
        obj2.setStrFirstName("BBB");
        
        Contact obj3 = new Contact();
        obj3.setStrSalutation("MR");
        obj3.setStrFirstName("CCC");
        lstContact.add(obj1);
        lstContact.add(obj2);
        lstContact.add(obj3);
    }
    
    public List<Contact> getLstContact() {
        return lstContact;
    }

    public void setLstContact(List<Contact> lstContact) {
        this.lstContact = lstContact;
    }
}

If I just enter 'X' in second column(First Name) filter and remove 'X' all values at first column (Salutation) are gone.

0

There are 0 answers