2 Replies Latest reply on May 3, 2006 12:32 PM by Jens Weintraut

    How to implement filters for a dataTable?

    Jens Weintraut Apprentice

      Hi folks,

      I've got a problem with implementing filters for a dataTable. I've two selectOneMenus like this:

      <h:selectOneMenu value="#{releaseSelector.selectedReleaseNumber}" valueChangeListener="#{releaseSelector.valueChanged}" onchange="submit()">
       <f:selectItems value="#{releaseSelector.releaseItems}" />
      </h:selectOneMenu>
      <h:outputText value=" " />
      <h:outputText value="#{ares_messages.testsequence}: " />
      <h:selectOneMenu value="#{testsequenceSelector.selectedTestsequenceNumber}" valueChangeListener="#{testsequenceSelector.valueChanged}" onchange="submit()">
       <f:selectItems value="#{testsequenceSelector.testsequenceItems}" />
      </h:selectOneMenu>


      Below is the dataTable showing the elements matching the filters. As you probably have seen I want the filters to be applied instantly after selecting a filter item.
      The filter B depends on filter A. So if another element is chosen in the filter A, filter B shows other elements than before.

      Now comes the tricky part: If the user selects an element in the filter A, which causes filter B to have only one element the filter isn't applied. I found two workarounds: Whether I add a submit button:
      <h:commandButton value="Just submit" type="submit" />

      which just submits the page or I add sth. like this:
      <h:outputText value="#{testactionTester.selectedTestsequenceToken}" style="visibility: hidden;" />

      Both workarounds work fine. The method in the second workaround just returns a string and does nothing else. It seems that the invocation is enough for JSF to show the current data.

      But I don't like this solutions. I think that I've forgotten sth or that there has to be a more elegant way. What do you think?

      Regards
      Newlukai