简体   繁体   中英

Searchable Selectonemenu in JSF2 or autoComplete in primefaces

Any one with an example of implementing a searchable selectonemenu in JSF2. One should be able to type and then select from the suggestions. The suggestions are many columns and are results from the database table. Tried this but i have failed to implement its custom converter using the autoComplete component of primefaces. Any one out there with a good lead/advise/url link on this. Thanks

Make use of an inputtext that the user types, and then a datatable that gets updated from the database on every keyup in the input text. Then you can use a button in a column to select from the suggestions or use jquery to put a listener on every row in the suggestions. Then use css to make a simulation of a selectonemenu

A short exemple:

View:

<h:inputText value="#{backBean.searchWord}">
    <p:ajax event="keyup" update="suggestionsTable"/>
    <p:ajax event="click" update="suggestionsTable"/>
</h:inputText>

<h:dataTable id="suggestionsTable" value="#{backBean.suggestionsList}" var="item" cellpadding="5" >
    <h:column>
        <h:outputText value="#{item.someItem}"></h:outputText>
    </h:column>
</h:dataTable>

Bean:

public class backBean {

    private List suggestionsList = new ArrayList();
    private String searchWord;

    public void setSearchWord(String searchWord) {
        suggestionsList = // items from your database
        this.searchWord = searchWord;
    }

    public String getSearchWord()
    {
        return this.searchWord;
    }

    public List getSuggestionsList()
    {
        return this.suggestionsList;
    }

    public void setSuggestionsList(List inList)
    {
        this.suggestionsList = inList;
    }

}

Thank to those who replied my post and sorry i took all this long to respond. I was able to find a solution using primefaces autoComplete component with Pojo by implementing a custom converter. More info https://www.primefaces.org/showcase/ui/input/autoComplete.xhtml

In case one needs more clarification, please let me know.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM