10 Replies Latest reply on Jun 1, 2011 3:15 AM by er.viveksrivastava

    insert new row in <d:dataTable> in single click?

    er.viveksrivastava Newbie

      Hi All

      I am using <t:dataTable> for creating data table . now i want to add new row in existing data table on click button.

      i attached image.

       

      new.bmp

        • 1. insert new row in <d:dataTable> in single click?
          Lukáš Fryč Master

          Hello, you can add new data model item into your collection which dataTable iterates over.

          • 4. insert new row in <d:dataTable> in single click?
            Daniel Lechner Novice

            When using the RichFaces' dataTable, you have to provide some datamodel via the parameter "value". When hitting the button, add one element to the datamodel in your backing-bean and rerender the dataTable

            • 5. insert new row in <d:dataTable> in single click?
              er.viveksrivastava Newbie

              I have't idea about datamodel. could you give example?

              • 6. insert new row in <d:dataTable> in single click?
                Daniel Lechner Novice

                I try to do so. The BackingBean:

                public class MyBackingBean
                {
                  [....]
                  private List listOfObjects;

                  {getter and setter for listOfObjects}

                  public void addDataObject()
                  {
                    listOfObjects.add(new MyDataObject('dummyName'));
                  }
                }

                 

                The XHTML-File:

                <rich:dataTable id="myTable">
                  {columns, ...}
                </rich:dataTable>
                <a4j:commandLink action="#{myBackingBean.addDataObject}" reRender="myTable" >
                  <h:outputText value="add element" />
                </a4j:commandLink>
                • 8. Re: insert new row in <d:dataTable> in single click?
                  er.viveksrivastava Newbie

                  this code not work plz help me another way.

                  • 9. Re: insert new row in <d:dataTable> in single click?
                    liumin hu Master

                    hi,

                     

                    post your backingbean and page code.

                    • 10. Re: insert new row in <d:dataTable> in single click?
                      er.viveksrivastava Newbie

                      BackingBean

                       

                       

                      public class BackingBean implements java.io.Serializable {

                       

                          private Integer columnNumber;

                          private Integer fileFieldId;

                          ArrayList<Integer> listObject=new ArrayList<Integer>();

                          //private List listObject;

                         

                          ArrayList<Integer> listObjectData (){

                              listObject.add(columnNumber);

                              listObject.add(fileFieldId);

                              return listObject;

                          }

                         

                          public Integer getColumnNumber() {

                              return columnNumber;

                          }

                          public void setColumnNumber(Integer columnNumber) {

                              this.columnNumber = columnNumber;

                          }

                          public Integer getFileFieldId() {

                              return fileFieldId;

                          }

                          public void setFileFieldId(Integer fileFieldId) {

                              this.fileFieldId = fileFieldId;

                          }

                         

                           public void addDataObject()

                            {

                              // listObject.add(new MyDataObject());

                            }

                       

                          public ArrayList<Integer> getListObject() {

                              return listObject;

                          }

                       

                          public void setListObject(ArrayList<Integer> listObject) {

                              this.listObject = listObject;

                          }

                      }

                       

                       

                      And my jsf page

                       

                       

                       

                       

                       

                      <t:dataTable id="mp_data_table1" var="list" rowClasses="ROW,ROW2"

                                              rows="2" preserveDataModel="false" preserveSort="true"

                                              bgcolor="#BED6F8" value="#{fileTemplateHandler.gcFileFormatBo}"

                                              width="750">

                                              <t:column width="100">

                                                  <f:facet name="header">

                                                      <h:outputText value="Column Number" style="width:75px" />

                                                  </f:facet>

                                                 

                                          <h:inputText id="column"

                                              value="#{fileTemplateHandler.columnNumber}"

                                              required="true" maxlength="100" style="width:70px;">

                                              <f:validateLength minimum="1" maximum="100" />

                                          </h:inputText>

                                                 

                                              </t:column>

                       

                                              <t:column width="120">

                                                  <f:facet name="header">

                                                      <h:outputText value="Select a Field" />

                                                  </f:facet>

                                                 

                                                  <h:selectOneMenu id="compaq"

                                                      value="#{fileTemplateHandler.fileFieldId}">

                                                      <f:selectItems value="#{fileTemplateHandler.gcFileFieldBoDrop}" />

                                                      <a4j:support event="change" execute="frm" render="frm"></a4j:support>

                                                  </h:selectOneMenu>                           

                                                  </t:column>

                                              <t:column width="115">

                                                  <f:facet name="header">

                                                      <h:outputText value="Delete Row" styleClass="formLabelswidth27" />

                                                  </f:facet>

                       

                                                  <a4j:region>

                                              <h:commandLink id="cmd_del_1"

                                                              action="#{fileTemplateHandler.dropDataType}" >

                                                              <h:graphicImage id="image" url="/images/b_drop.png">

                                                              </h:graphicImage>

                                                           <a4j:actionparam  name="id1" assignTo="#{fileTemplateHandler.fileFieldId}" value="#{list.fileFieldId}" />

                                                              </h:commandLink>

                                             

                                              </a4j:region>

                                              </t:column>

                                          </t:dataTable>