8 Replies Latest reply on Aug 2, 2007 7:26 PM by damianharvey

    dynamic dataTable

    mrohad

      I would like to add new line to dataTable
      as a new row of input boxes

      I'll fill the new row with data and press "save"
      then the row will become reguler row in the table.

      is there any JSF componenet that can do that?
      otherwise if I want to be able to add more then one row before saving
      how can I outject the information to seam componenet?

        • 1. Re: dynamic dataTable
          mrohad

          if I wasn't clear this is what I want:

          _________________________
          |____col-1____|____col-2____|
          |___fdfdsfdsf__|___dsfdsf____| << data from DB
          |___dsfdsf____|___dsfdsf____| << data from DB
          |_ _ _ _ __ _ _ | _ _ _ _ _ _ _| << New Row1 using input boxes Added
          |_ _ _ _ __ _ _ | _ _ _ _ _ _ _| << New Row2 Added

          [save button]

          • 2. Re: dynamic dataTable
            pmuir

            Add an empty object (of the correct type) to the backing list.

            • 3. Re: dynamic dataTable
              mrohad


              what about UI ,
              shouldI add the new line with javascript or there is control that already do that?

              • 4. Re: dynamic dataTable
                pmuir

                No, do using a s:button or a h:commandButton.

                • 5. Re: dynamic dataTable
                  mrohad

                  so let see if I understood..

                  the s:button add new Elemnt to the List
                  and go back to the page?
                  now I've the check if the element is empty then I put inputbox instead of lables?
                  and of course I better do so with ajax , right?

                  • 6. Re: dynamic dataTable
                    damianharvey

                    Use ajax. Much nicer ;)

                    <rich:dataTable id="myTableId" value="#{myBean.myList}" var="row">
                     ...etc
                    

                    <a4j:commandLink action="#{myBean.addNewListEntry}" reRender="myTableId">Add New Row</a4j:commandLink>
                    

                    public void addNewListEntry() {
                     this.myList.add(new WhateverObject());
                    }
                    



                    • 7. Re: dynamic dataTable
                      mrohad

                      thanks!
                      i've one more open questions
                      my exisitng data is not editable andthe new rowis editable
                      how do you suggest I'll make the new row made out of input boxes
                      and the rest of the rowsout of just labels?

                      • 8. Re: dynamic dataTable
                        damianharvey

                        There are 2 ways that I can think of right now (a bit late for me so sorry if missed some):

                        1. Build up a list of Beans where the bean has a property that determines whether a value is present or not.

                        2. Use the EL to figure out if the row is new.

                        #2 would be my choice. You could so something like:

                        <rich:column>
                         <s:span rendered="#{row.something !=null}">
                         #{row.whatever}
                         </s:span>
                         <s:span rendered="#{row.something ==null}">
                         <h:inputText value="#{row.whatever}"/>
                         </s:span>
                        </rich:column>
                        


                        Cheers,

                        Damian