Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Primesfaces : how to get the value of a Filter column text

given the following primefaces Data

<p:dataTable value="#{cc.attributes.playerCollection}" var="player"
    widgetVar="playerWidgetTable" emptyMessage="#{uimsg.ui_not_recordsfound}">
    <!-- filter event handler  -->
    <p:ajax event="filter" listener="#{cc.attributes.viewBean.listenFilter}" update="@this"/>

    <!-- Player first name  -->
    <p:column id="firstnameColumn" headerText="#{uimsg.firstname}"
        filterBy="#{player.firstName}" filterMatchMode="contains">
        <h:outputText value="#{player.firstName}" />
    </p:column>
</p:dataTable>

how does someone get (on the server side) the filter "Text" value, given by the user in the filter textcolumn ?

i tried to listen to the filter event with "listenFilter":

@ManagedBean
@ViewScoped
public class PlayerListBean implements Serializable {

......

    public void listenFilter(FilterEvent event) {
        // update datasource
        Map<String, String> tempString = event.getFilters();

        System.out.println("size filter: "+ tempString.size());
        for (String key : tempString.keySet()) {
            System.out.println("key: " + key + " \t values: "
                    + tempString.get(key));

        }

    }

}

but I can't start something with it. are they any other options ? like working with the DataTable as a bound Component, or else ?

thanks

like image 577
arthur Avatar asked Oct 25 '25 05:10

arthur


1 Answers

This works just fine for me...

public void listenFilter(FilterEvent event) {

    DataTable table = (DataTable) event.getSource();
    Map<String, String>  filters = table.getFilters();
    //grab the value from the required map key (somePropertyName if your filterBy 
     looks like filterBy="#{myBean.somePropertyName}") ... 

}
like image 106
Daniel Avatar answered Oct 26 '25 22:10

Daniel