Pergunta

I have a use case where I plan to have a rich:pickList so that a user can pick multiple items from a list. But, in few cases the number of items in pickList are too large(in hunderds and sometimes in thousands) and it is not practical for the user to scroll the whole length down. So, is there a way i can have a search box above the lefthand side list of the pickList? It should be similar to that of the autoComplete component so that there are always 10 items in the pickList, which are the closest matches of the keywords entered in the search box.

I use richfaces 4 and JSF 2.0.

Foi útil?

Solução

What about this?

Page:

<h:inputText value="#{bean.prefix}">
    <a4j:ajax event="keyup" render="list" />
    <a4j:ajax event="focus" oncomplete="saveList()" />
</h:inputText>

<a4j:region>
    <rich:pickList id="list" value="#{bean.selectedList}">
        <f:selectItems value="#{bean.filteredList}" var="str" itemLabel="#{str}" itemValue="#{str}" />
    </rich:pickList>
</a4j:region>

<a4j:jsFunction name="saveList" execute="list" />

Bean:

// fullList - contains everything    

public List<String> getFilteredList() {        
    List<String> filteredList = new ArrayList<String>();
    Set<String> filteredSet = new TreeSet<String>();

    for (String s : fullList) {
        if (s.startsWith(getPrefix())) {
            filteredSet.add(s);
        }

        if (filterSet.size() > 9) {
            break;
        }
    }

    filteredSet.addAll(selectedList);
        // we need to add the selected items so they would be rendered
        // target list needs to be a subset of the source list

    filteredList.addAll(filteredSet);

    return filteredList;
}
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top