Hyun Hyun - 1 month ago 17
Ajax Question

JSF ajax search with data table

I have a controller method that reads a list of data from database and currently, a data table takes the list from the controller.

<h:dataTable
var="task"
value="#{taskController.readByUsername()}">


I want to use the Ajax to search tasks by the task name and display tasks that contain the name searched by user dynamically. How can I achieve this?
Thank you!

Answer

Have you tried to use primefaces or richfaces or something else?

For instance, in primefaces you can it like this:

<p:dataTable var="task" value="#{taskController.readByUsername()}" paginator="true" rows="10" id="tasks" lazy="true" ...>
    ...
    <p:column headerText="Task" sortBy="#{var.name}" filterBy="#{var.name}">
        <h:outputText value="#{var.name}" />
    </p:column>
    ...
</p:dataTable>

Note, the code above is not a working one. It just gives an idea how to dynamically show tasks by some attribute. The primefaces components already have all ajax features (based on jquery).

I recommend you to use something like primefaces if you're working with jsf and need to have ajax features in your web application.

Comments