Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Filter DataTable in Primefaces only works once

I'm trying to filter a dataTable using Primefaces much like this example. (In a web browser) I type the text I want to filter by, it works once but when I remove the text I've written the result stays the same when it should go back to it's original state.

So it works once and then won't respond. (I can remove or re-type the filter text I've written but it does not affect the table anymore)

Sorry about the weird attribute names in the code, bear with me. :)

xhtml-page:

<h:form>
    <p:dataTable var="aggr" value="#{aggregationManagedBean.logiskAdressatModel}"
             widgetVar="aggrTable"
             emptyMessage="No aggr found with given criteria">

        <f:facet name="header">
            <p:outputPanel>
                <h:outputText value="Filter:" />
                <p:inputText id="globalFilter" onkeyup="aggrTable.filter()" />
            </p:outputPanel>
        </f:facet>
        <p:column filterBy="#{aggr.name}"> 
            <f:facet name="header">
                <h:outputText value="Name" /> 
            </f:facet>
            <h:outputText value="#{aggr.name}" /> 
        </p:column>
    </p:dataTable>
</h:form>

backing bean:

@ManagedBean
@SessionScoped
public class AggregationManagedBean {

    private List<LogiskAdressat> logiskaAdressater;
    private DataModel<LogiskAdressat> logiskAdressatModel;

    public AggregationManagedBean() {
        logiskaAdressater = getLogiskaAdressater();
        logiskAdressatModel = new ListDataModel<LogiskAdressat>(logiskaAdressater);
    }

    private static List<LogiskAdressat> getLogiskaAdressater(){
        List<LogiskAdressat> logiskaAdressater = new ArrayList<LogiskAdressat>();

        logiskaAdressater.add(new LogiskAdressat("01 addr_id 01", "Joe"));
        logiskaAdressater.add(new LogiskAdressat("02 addr_id 02", "John"));        
        logiskaAdressater.add(new LogiskAdressat("03 addr_id 03", "Jake"));

        return logiskaAdressater;
    }

    public DataModel<LogiskAdressat> getLogiskAdressatModel() {
        return logiskAdressatModel;
    }

    public void setLogiskAdressatModel(DataModel<LogiskAdressat> adressatModel) {
        this.setLogiskAdressatModel(adressatModel);
    }

}

like image 401
Dennis S Avatar asked Dec 04 '25 14:12

Dennis S


1 Answers

Is LogiskAdressat Serializable?

If not, then try making it Serializable -

public class LogiskAdressat implements Serializable {

    //....
like image 112
Bhesh Gurung Avatar answered Dec 07 '25 02:12

Bhesh Gurung



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!