0

I Need to implement same thing in jsf using jsf builtin components. The problem I am not able to find the list attribute to bind the <datalist>. Please help me how can I do that.

<input id="something" list="somethingelse"/>
        <datalist id="somethingelse">
            <option value="Something"></option>
            <option value="Something Else"></option>
            <option value="Another One"></option>
            <option value="Alpha"></option>
            <option value="Bravo"></option>
            <option value="Charlie"></option>
            <option value="Delta"></option>
            <option value="Echo"></option>
            <option value="Foxtrot"></option>
            <option value="Gamma"></option>
        </datalist>
7
  • why do you need this? And the answer is: There is no such option in the JSF input Commented Sep 15, 2016 at 12:56
  • I have to use <h:inputtext> in my page. I need to know how can i use in <h:inputtext> Commented Sep 15, 2016 at 13:07
  • Sorry, to repeat myself, but let me formulate it a little more clearly. Why do you need to use an <h:inputText> (with a dataList) instead of an <h:selectOneMenu>? And did you try to use a jsf2.2 passthtrough attribute? Commented Sep 15, 2016 at 13:12
  • Sir I need to implement search box with suggestions like facebook etc. I have tried <h:selectOneMenu> but it is not full filling the requirements Commented Sep 15, 2016 at 13:34
  • Ahhhh.... See... Please, next time add things like this to the question. It makes it way more clear. And if you even add why it does not meet the requirements, it would even be better. catb.org/esr/faqs/smart-questions.html#goal. Still, the suggestion to try to use passthrough attributes might help. Commented Sep 15, 2016 at 13:40

1 Answer 1

2

You can use jsf passtrough attributes for this.

<input id="something" list="somethingelse"/>

becomes

<h:inputText pt:list="somethingelse" />

So the following full example works:

<html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:pt="http://xmlns.jcp.org/jsf/passthrough">

<h:head />

<h:body>
    <h:form>
        <h:inputText pt:list="somethingelse" />
        <datalist id="somethingelse">
            <option value="Something"></option>
            <option value="Something Else"></option>
            <option value="Another One"></option>
            <option value="Alpha"></option>
            <option value="Bravo"></option>
            <option value="Charlie"></option>
            <option value="Delta"></option>
            <option value="Echo"></option>
            <option value="Foxtrot"></option>
            <option value="Gamma"></option>
        </datalist>
    </h:form>

</h:body>
</html>

But keep in mind that you need to have the full list of options on the client-side upfront. No easy populating from a database based on the characters that are typed.

If you are allowed to use something like PrimeFaces, its p:autoComplete is way more powerful

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.