10 Replies Latest reply on Jul 24, 2008 5:50 AM by Kashif Nazar

    Table Control

    Kashif Nazar Newbie


      Richfaces is a wonderful library. I have to use a table control to input values, every row for an object. This is fine. But I have to have a text field associated with that table. Whatever number should I enter in the text field, the number of rows in that table should change accordingly. There is a similar example on


      But it does not have the source code of the backing beans. Can I have the full source code to this example.



        • 1. Re: Table Control
          Ilya Shaikovsky Master

          dataFilterSlide is a component which filters data by some field.

          But if you need only limit number of rows to be displayed there's no need in such control. You just need something like:

          <h:inputText value="#{someBean.someInt}"/>
          rich:dataTable rows="#{someBean.someInt}">

          B.t.w. Link to demo sources in our wiki.

          • 2. Re: Table Control
            Kashif Nazar Newbie

            I have to use AJAX. So the page does not need to refresh.

            I have tried a piece of code but It is not working. This works when I re-render an outputText, but not with other components. I think this works only for span tags.

            <h:inputText value="#{subscriptionService.numberOfTokens}">
             <a4j:support event="onkeyup" reRender="out" />
            <a4j:outputPanel id="out">
             <h:inputText value="#{subscriptionService.numberOfTokens}" />

            • 3. Re: Table Control
              Ilya Shaikovsky Master

              this also described in our FAQ. wrap first input with a4j:region ;)

              • 4. Re: Table Control
                Kashif Nazar Newbie

                thanks, it's working

                • 5. Re: Table Control
                  Kashif Nazar Newbie

                  I am one more little problem.

                  I have an arraylist associated with the datatable. The number of rows are dependent on the number of items in this array list. When I edit the input text box, the setter of the related property is called. What I have is done, is that in the setter I initialize the array list with that number of elements.

                  Now, this setter is called twice. First when I change the value in the text box, it is called through AJAX, and secondly, when the form is submitted.

                  As a result, when the form is submitted, the setter of the text field re-instantiates the array list.

                  Is there anyway that the arraylist instantiation code be placed in some other function other than the setter of the text field? I want to instantiate the array list only when the value is changed, but not when the setter is called

                  • 6. Re: Table Control
                    Kashif Nazar Newbie

                    I have refined my work to some extent. I need the answer to a simple question. How can I get the value in the following function.

                    public void updateArrayList(ActionEvent e)
                    //value of the bean.numberOfRows needed here

                    In jsf, this is my code.

                    <h:inputText style="width: 39px" id="numberOfRows"

                    <a4j:support event="onkeyup" reRender="out" actionListener="#{bean.updateArrayList}" />



                    • 7. Re: Table Control
                      Mikael Andersson Master

                      The updateArrayList( ActionEvent ) is in the bean class right? If so isn't the numberOfRows property already set?

                      • 8. Re: Table Control
                        Kashif Nazar Newbie

                        Now I am able to access that. Thanks.

                        Now, my datatable is not mapping with the array list.

                        <h:dataTable value="#{bean.arrayList}" var="item">
                        <inputText value="item.prop1" />

                        The array list is not populating

                        • 9. Re: Table Control
                          Mikael Andersson Master

                          So you have

                          public List getArrayList(){ return theArrayList; }

                          in your bean class? If not you should add it.

                          the datatable code you've posted is not correct, it should be something like:

                          <h:dataTable value="#{bean.arrayList}" var="item">
                           <h:inputText value="#{item.prop1}"/>

                          • 10. Re: Table Control
                            Kashif Nazar Newbie

                            Yes! I have the getArrayList(); method

                            and sorry for the mistake. Thanks for the correction