Domanda

I was wondering if it's possible to have a two fields filter with a picklist of primefaces. I tried this but it's not working. I would like to filter on firstname and name but they are in two different fields.

<p:pickList value="#{bean.usersDualModel}" var="user" 
    itemValue="#{user}" itemLabel="#{user.firstname} #{user.name}"  
    converter="user" showSourceFilter="true" showTargetFilter="true" 
    filterMatchMode="contains" >

    <p:column>  
        <h:outputText value="#{user.firstname} #{user.name}" />  
    </p:column>

</p:pickList>

Thanks

È stato utile?

Soluzione 2

This is not possible with the default component. However you can create a custom filter (example taken from Primefaces manual):

<p:pickList value="#{pickListBean.cities}" var="city" itemLabel="#{city}" 
    itemValue="#{city}" showSourceFilter="true" showTargetFilter="true
    filterMatchMode="custom" filterMatchMode="myfilter">
</p:pickList>

function myfilter(itemLabel, filterValue) {
//Filter for firstname or name
//return true or false
}

Of course you can also create a custom component by extending the primefaces picklist or create two seperate inputtext fields and fire any filtering manually with javascript/jquery.

Altri suggerimenti

In fact, I think it's possible because it's working know with the code I posted above. However, the Javascript method is easy to set up with two fields so I could have done it quickly. Thanks for the suggestion.

The reason it wasn't working the first time is that there is an bug in Primefaces for the picklist filter and it's not patched officialy. The filter mode stayed in startsWith whatever the value I entered.

So my picklist is still

<p:pickList value="#{bean.usersDualModel}" var="user" 
    itemValue="#{user}" itemLabel="#{user.firstname} #{user.name}"  
    converter="user" showSourceFilter="true" showTargetFilter="true" 
    filterMatchMode="contains" > ...

And there is a custom patch by know. Here is the link of the report.

https://code.google.com/p/primefaces/issues/detail?id=5234
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top