cancel
Showing results for 
Search instead for 
Did you mean: 

Dynamic Table

Former Member
0 Kudos

Hi Experts,

I have an issue with Dynamic Table creation. This is the situation. I have an XML Where in i store table rows and columns. when the page loads i have to read the XML and i have to create row and columns dynamically as in the XML. I have done this . Problem is , i user wants to add a new column. i am giving one pop up window , where in i am getting column name. when pop up window closed, the dynamic table was not there .

What i am doing wrong?

I am creating dynamic table in init method. is it if control goes to anther window all context info will be lost?

Please help me on this.

Thank you,

Regrads,

Senthil

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi,

"I am creating dynamic table in init method. is it if control goes to anther window all context info will be lost?"

Dont store the view instance.

Create the table in the wdDomidifyView based on a condition either isFirstTime or else your custom one.

It would be really helpfull if you could post the code.

Regards

Ayyapparaj

Former Member
0 Kudos

Hi Ayyapparaj,

This is the code

public void wdDoInit()

{

//@@begin wdDoInit()

//Add Buttons

IWDView view = (IWDView)this.wdControllerAPI;

XMLParseWrite pars = new XMLParseWrite();

IWDNodeInfo tabNode=wdContext.getNodeInfo().addChild("sharedData", null,true, true, true,false,true,false,null,null,null);

IWDTransparentContainer root = (IWDTransparentContainer)view.getRootElement();

// Add Master Data Button Creation

IWDButton addMasterData = (IWDButton)view.createElement(IWDButton.class,"AddMasterData");

addMasterData.setText("AddMasterData");

root.addChild(addMasterData);

// Action Creation for Add masterData Button

IWDAction addmd = wdThis.wdCreateAction(IPrivateMDMView.WDActionEventHandler.GENERIC_ACTION, "AddMasterdataAction");

addMasterData.setOnAction(addmd);

WDDeployableObjectPart dobp = wdComponentAPI.getDeployableObjectPart();

String path=null;

try{

path = WDURLGenerator.getResourcePath(dobp,"TestRun.xml");

}catch(WDAliasResolvingException e){

wdComponentAPI.getMessageManager().reportSuccess(e.getMessage());

}

File f = new File(path);

// wdComponentAPI.getMessageManager().reportSuccess(path"status"f.exists());

Document d = pars.parseXML(path);

NodeList root_nod = d.getElementsByTagName("SharedMasterData");

// Creating Dynamic nodes and data for Master Data

ArrayList al = pars.getChileNodesByName(root_nod.item(0), "LineItem");

Node lineitem[] = new Node[al.size()];

Iterator it = al.iterator();

int len= 0;

while(it.hasNext()){

lineitem[len] = (Node)it.next();

len++;

}

Node masterData[] = pars.getOnlyElementChildNodes(lineitem[0].getChildNodes());

String[] masterDataName = new String[masterData.length];

for(int i = 0;i < masterData.length;i++)

{

Node n = masterData<i>;

masterDataName<i> = n.getNodeName();

tabNode.addAttribute(masterDataName<i>, "ddic:com.sap.dictionary.string");

}

// IWDAttributeInfo tabAttrib1 = tabNode.addAttribute("ProductID", "ddic:com.sap.dictionary.string");

// IWDAttributeInfo tabAttrib2 = tabNode.addAttribute("PartyID", "ddic:com.sap.dictionary.string");

// IWDAttributeInfo tabAttrib3 = tabNode.addAttribute("Count", "ddic:com.sap.dictionary.string");

IWDTable table = (IWDTable)view.createElement(IWDTable.class,"TestDataTable");

table.bindDataSource(tabNode);

// table.setCompatibilityMode(WDTableCompatibilityMode.AUTO);

table.setDesign(WDTableDesign.ALTERNATING);

IWDTableColumnGroup MasterDataGroup = (IWDTableColumnGroup)view.createElement(IWDTableColumnGroup.class,"MasterData");

IWDCaption caption = (IWDCaption)view.createElement(IWDCaption.class,"colGroupCaption");

caption.setText("MasterData");

MasterDataGroup.setHeader(caption);

for(int i=0;i<masterDataName.length;i++)

{

IWDAttributeInfo attrbt = tabNode.getAttribute(masterDataName<i>);

IWDTableColumn col = (IWDTableColumn)view.createElement(IWDTableColumn.class,masterDataName<i>);

IWDCaption colcap1 = (IWDCaption)view.createElement(IWDCaption.class,"MasterDataCaption"+i);

colcap1.setText(masterDataName<i>);

col.setHeader(colcap1);

IWDTextView celleditor = (IWDTextView)view.createElement(IWDTextView.class,"MDtextView"+i);

celleditor.bindText(attrbt);

col.setTableCellEditor(celleditor);

MasterDataGroup.addColumn(col);

}

// Static data Reacding part

table.addGroupedColumn(MasterDataGroup);

NodeList st_root_nod = d.getElementsByTagName("SharedStaticData");

// Creating Dynamic nodes and data for Master Data

ArrayList al2 = pars.getChileNodesByName(st_root_nod.item(0), "LineItem");

Node st_lineitem[] = new Node[al2.size()];

Iterator it2 = al2.iterator();

int len2= 0;

while(it2.hasNext()){

st_lineitem[len2] = (Node)it2.next();

len2++;

}

Node staticData[] = pars.getOnlyElementChildNodes(st_lineitem[0].getChildNodes());

// wdComponentAPI.getMessageManager().reportSuccess("Size"al2.size()staticData.length);

String[] staticDataName = new String[staticData.length];

for(int i = 0;i < staticData.length;i++)

{

Node n = staticData<i>;

staticDataName<i> = n.getNodeName();

tabNode.addAttribute(staticDataName<i>, "ddic:com.sap.dictionary.string");

}

if(staticData.length>0)

{

IWDTableColumnGroup staticDataGroup = (IWDTableColumnGroup)view.createElement(IWDTableColumnGroup.class,"StaticData");

IWDCaption staticcaption = (IWDCaption)view.createElement(IWDCaption.class,"colGroupCaption1");

staticcaption.setText("StaticData");

staticDataGroup.setHeader(staticcaption);

for(int i=0;i<staticDataName.length;i++)

{

IWDAttributeInfo attrbt = tabNode.getAttribute(staticDataName<i>);

IWDTableColumn col1 = (IWDTableColumn)view.createElement(IWDTableColumn.class,staticDataName<i>);

IWDCaption colcap1 = (IWDCaption)view.createElement(IWDCaption.class,"StaticDataCaption"+i);

colcap1.setText(staticDataName<i>);

col1.setHeader(colcap1);

IWDTextView celleditor = (IWDTextView)view.createElement(IWDTextView.class,"STtextView"+i);

celleditor.bindText(attrbt);

col1.setTableCellEditor(celleditor);

staticDataGroup.addColumn(col1);

}

table.addGroupedColumn(staticDataGroup);

}

// table.addGroupedColumn(col2);

table.createLayoutData(IWDRowHeadData.class);

table.setWidth("500");

IWDNode node = (IWDNode)wdContext.getChildNode("sharedData",0);

for(int i=0;i<lineitem.length;i++)

{

IWDNodeElement ele = (IWDNodeElement)node.createElement();

Node masterDatas[] = pars.getOnlyElementChildNodes(lineitem<i>.getChildNodes());

for(int j=0;j<masterDatas.length;j++)

{

ele.setAttributeValue(masterDatas[j].getNodeName(), masterDatas[j].getTextContent());

}

Node staticDatas[] = pars.getOnlyElementChildNodes(st_lineitem<i>.getChildNodes());

for(int k=0;k<staticDatas.length;k++)

{

ele.setAttributeValue(staticDatas[k].getNodeName(), staticDatas[k].getTextContent());

}

node.addElement(ele);

}

root.addChild(table);

//@@end

}

Former Member
0 Kudos

Hi,

Move the UI creation to the wdDoMoidify

Instead of this

IWDView view = (IWDView)this.wdControllerAPI;

use

IWDView view = view (param which is available as part of the wdDoModify)

Regards

Ayyapparaj

Former Member
0 Kudos

Hi Ayyapparaj,

I tried that. when page loads, i am getting table and all columns and rows. But after pop get destroyed, i am getting empty screen.

Regards,

Senthil

Former Member
0 Kudos

Hi,

If the screen is totally empty their could be two reasons

1) Infinite loop

2) Usage of following code

IWDTransparentContainer container;

container.destroyAllChildren();

Regards

Ayyapparaj

Answers (0)