Question

I have a jsf page that succesfully pulls data from my data bean when the page first loads.

What I want is for the datatable to use text input from a inputText component in the jsf, and then use that within the call the jsf bean and generate the table.

How would I go about doing this?

Specifically what I want is

  • Take text input from inputText JSF component
  • On commandButton JSF component click
  • Update the dataTable using the inputText as a parameter with the bean call

        <h:dataTable value="#{movie.getSearchMovieList('car')}" var="c"
                     styleClass="order-table"
                     headerClass="order-table-header"
                     rowClasses="order-table-odd-row,order-table-even-row"
                     >
    
            <h:column>
                <f:facet name="header">
                    Movie ID
                </f:facet>
                #{c.itemid}
            </h:column>
    
            <h:column>
                <f:facet name="header">
                    Title
                </f:facet>
                #{c.title}
            </h:column>
        </h:dataTable>
    
Was it helpful?

Solution

Create a field in the managed bean to hold the default value when navigating:

private String filter = "car"; // + getter/setter

Then, in the view:

<h:form>
    <h:inputText label="Type search filter :" value="#{movie.filter}" />
    <h:dataTable value="#{movie.getSearchMovieList(movie.filter)}" var="c" ... >
        ...
    </h:dataTable>

    <h:commandButton value="Search" /> // no action attribute means refreshing
<h:form>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top