1 Reply Latest reply on Mar 2, 2011 5:24 PM by Ramkumar Pillai

    Dynamic DataTable In SEAM2.2.0

    Ramkumar Pillai Newbie

      hi, im in research of developing a dynamic DataTable using SEAM 2.2.0 please help me the last step


      /// Use the below code for your xhtml/








      <ui:composition xmlns="http://www.w3.org/1999/xhtml"
              xmlns:s="http://jboss.com/products/seam/taglib"
              xmlns:ui="http://java.sun.com/jsf/facelets"
              xmlns:f="http://java.sun.com/jsf/core"
              xmlns:h="http://java.sun.com/jsf/html"
              xmlns:rich="http://richfaces.org/rich"
              xmlns:a4j="http://richfaces.org/a4j" >
              <ui:define name="body">
                      
                      <rich:panel header="Model List Header">
                              <div>
                                      <rich:dataTable value="#{modelList}" var="model" width="750"> <!-- here is the List of Object -->
                                              <rich:columns value="#{columns}" var="column" index="ind" id="column#{ind}"> <!-- Here the List of private Member Variable List of that object-->
                                                      <f:facet name="header">#{column}</f:facet> <!-- Printing all Field names as Table header-->
                                                      <h:outputText value="#{'model.'.concat(column)}" /> <!-- Should print all the value-->
                                              </rich:columns>
                              </rich:dataTable>
                              </div>
                      </rich:panel>
              </ui:define>
              
      </ui:composition>
      





      // Use the below code in any of your Bean/





      @Factory("columns")
              public List<String> columns(){
                      List<String> columns = new ArrayList<String>();
                      Class c = MediationFileDetail.class;
                      for(Field field : c.getDeclaredFields()){
                              columns.add(field.getName());
                      }
                      System.out.println(columns);
                      return columns;
              }
              
              @Factory("modelList")
              public List<MediationFileDetail> fillModelList(){
                      List<MediationFileDetail> modelList = new ArrayList<MediationFileDetail>();
                      for(long i=1;i<20;i++){
                              MediationFileDetail mfd = new MediationFileDetail(i, i*100, i+"Name", i+"folder", "Date"+i, "Path"+i);
                              modelList.add(mfd);
                      }
                      System.out.println(modelList);
                      return modelList;
              }



      below is the out put im getting now



      id fileSize fileName fileDate fileModifiedDate fileOrginalPath
      model.id model.fileSize model.fileName model.fileDate model.fileModifiedDate model.fileOrginalPath
      model.id model.fileSize model.fileName model.fileDate model.fileModifiedDate model.fileOrginalPath
      model.id model.fileSize model.fileName model.fileDate model.fileModifiedDate model.fileOrginalPath


      i need to get the value some how





        • 1. Re: Dynamic DataTable In SEAM2.2.0
          Ramkumar Pillai Newbie

          P.T.O
          Here we go with the dynamic Datatable Code




          <h:outputText value="#{'model.'.concat(column)}" /> <!-- Should print all the value--> Replace this line with below line 
          <h:outputText value="#{model.getColumnValue(column)}" /> <!-- This will send the field name from the column list below mothod -->
          




          Write the below code on the Model POJO


               


          public String getColumnValue(String column){
                    System.out.println(this.fileName+"  ," +column);
                    String mname = "get" + StringUtils.capitalize(column);
                    String value = "";
                   Method method;
                    try {
                         method = this.getClass().getMethod(mname);
                          Object  result = method.invoke(this);
                          value = result == null ? "" : result.toString();
                    } catch (Exception e) {
                         e.printStackTrace();
                    }
                    return value; 
               }