on 03-07-2008 2:14 PM
HI,
How can i create a webdynpro Table dynamically(At runtime). with out using a table ui. What api should i use for it.? Does anybody has the code for that? Can anybody please help me out in this issue?
Regards,
Divya
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
What does that mean "without a table ui"?
Armin
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi
Use This 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 Nodehttp://al.size();
Iterator it = al.iterator();
int len= 0;
while(it.hasNext()){
lineitemlen = (Node)it.next();
len++;
}
Node masterData[] = pars.getOnlyElementChildNodes(lineitem[0].getChildNodes());
String[] masterDataName = new Stringhttp://masterData.length;
for(int i = 0;i < masterData.length;i++)
{
Node n = masterData;
masterDataName = n.getNodeName();
tabNode.addAttribute(masterDataName, "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);
IWDTableColumn col = (IWDTableColumn)view.createElement(IWDTableColumn.class,masterDataName);
IWDCaption colcap1 = (IWDCaption)view.createElement(IWDCaption.class,"MasterDataCaption"+i);
colcap1.setText(masterDataName);
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 Nodehttp://al2.size();
Iterator it2 = al2.iterator();
int len2= 0;
while(it2.hasNext()){
st_lineitemlen2 = (Node)it2.next();
len2++;
}
Node staticData[] = pars.getOnlyElementChildNodes(st_lineitem[0].getChildNodes());
// wdComponentAPI.getMessageManager().reportSuccess("Size"+al2.size()+staticData.length);
String[] staticDataName = new Stringhttp://staticData.length;
for(int i = 0;i < staticData.length;i++)
{
Node n = staticData;
staticDataName = n.getNodeName();
tabNode.addAttribute(staticDataName, "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);
IWDTableColumn col1 = (IWDTableColumn)view.createElement(IWDTableColumn.class,staticDataName);
IWDCaption colcap1 = (IWDCaption)view.createElement(IWDCaption.class,"StaticDataCaption"+i);
colcap1.setText(staticDataName);
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.getChildNodes());
for(int j=0;j<masterDatas.length;j++)
{
ele.setAttributeValue(masterDatas[j].getNodeName(), masterDatas[j].getTextContent());
}
Node staticDatas[] = pars.getOnlyElementChildNodes(st_lineitem.getChildNodes());
for(int k=0;k<staticDatas.length;k++)
{
ele.setAttributeValue(staticDatas[k].getNodeName(), staticDatas[k].getTextContent());
}
node.addElement(ele);
}
root.addChild(table);
//@@end
}
Regards
Chandran S
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
93 | |
10 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.