Technology Blogs by Members
Explore a vibrant mix of technical expertise, industry insights, and tech buzz in member blogs covering SAP products, technology, and events. Get in the mix!
cancel
Showing results for 
Search instead for 
Did you mean: 
Former Member
0 Kudos

Uploading Excel files of unkown structure to Web Dynpro, Part One - PreviewUploading Excel files of unkown structure to Web Dynpro, Part Two - Reading in the excel

Creating Dynamic table UI element

In this part of my blog I will show you how to dynamically create a table UI element to
host the excel table we just uploaded. In the method wdDoModify() we add the following code:

try

{

   //Get  the row that contains the header
    ArrayListrow = getHeader_row();
    IWDTransparentContainer container = (IWDTransparentContainer)      
    view.getElement("TargetContainer");

    if (!firstTime)
   {

      // Get  node 'Table'
     IWDNodeInfo tableInfo = wdContext.getChildNode("Table", 0).getNodeInfo();

     //Each UI element receives an I.D on creation. If the I.D exists get it and destroy the element
     String id = wdContext.currentViewElement().getTableId();

      if (id != null)
     {
        view.getElement(id).destroy();
     }

    IWDTable tableUI = view.createElement(IWDTable.class);
    tableUI.setDisplayEmptyRows(false);

    // save the I.D.  for later
    wdContext.currentViewElement().setTableId(tableUI.getId());

     if (row.size() > 0)
    {      
     //for each row of the table create all columns and insert a text view into each cell       
      for
(int j = 0; j < row.size(); j++)
     {

         String col_name = (String) header_row.get(j) + j;
         if (col_name == null || col_name.equalsIgnoreCase(""))
        {
                      continue;
        }

         // column
         IWDTableColumn col = view.createElement(IWDTableColumn.class, col_name);

         // header
         IWDCaption header = view.createElement(IWDCaption.class, "cap__" + j);

          // text view
         IWDTextView textView = view.createElement(IWDTextView.class, "text_"+j);
         header.setText((String) header_row.get(j));

         col.setHeader(header);
         textView.bindText(tableInfo.getAttribute(col_name));
         col.setTableCellEditor((IWDTextView) textView);
         tableUI.addGroupedColumn(col);

      }

        //bind the Table UI element to the context
        tableUI.bindDataSource(tableInfo);

        // add the Table UI element to the view container

        if (container != null)
       container.addChild(tableUI);

  }

 }

}

catch (Exception e)

{

   msgMgr.reportException(e.getLocalizedMessage());

}

Labels in this area