cancel
Showing results for 
Search instead for 
Did you mean: 

create Table and add data

Former Member
0 Kudos

Hi all,

I need some info about dynamically updating table.

I have 2 rows of data. For example say

Column names : Name City

-


row1 : Peter London

row2 : Carol Texas

I am getting data (peter/London , carol/Texas) and I want to display in Webdynpro table.

Could some one please send me code how to do this.

I created table and tried to map the context values to

(Node:table ,Attribue:name ,city ) but it is giving error.So I would appreciate if some one can respond me with answer code and helping URLS. I promise to award full marks for the right solution..Please respond .

Thank you

Regards

Maruti

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi

Create the Node:table with cardinality o..n

|-name

|-city

//Node Creation

IPrivatre<ViewName>.I<TableName>Node node=wdContext.node<TableName>();

node.invalidate();

//Inside the loop or Database Resultset

IPrivatre<ViewName>.I<TableName>Element element=wdContext.create<TableName>Element();

element.set<name>("<name>");

element.set<city>("<city>");

node.addElement(element);

See this Thread

Kind Regards

Mukesh

sridhar_k2
Active Contributor
0 Kudos

Hi,

What is the error? Error in adding new rows or updating existing row?

<b>Adding new rows</b>

ITableElement table = null;

int size = 2; //get the size from model, in ur program

for(int i=0;i<size;i++){

table = (ITableElement)wdContext.nodeTable().createTableElement();

table.setCity("London"); //in your case, get dynamically city and name

table.setName("Peter");

wdContext.nodeTable().addElement(table);

}

<b>Updating existing row</b>

ITableElement tableEle = (ITableElement)wdContext.nodeTable().getElementAt(wdContext.nodeTable().getLeadSelection());

if(tableEle != null){

tableEle.setCity("Blore");

tableEle.setName("SAP");

}

Regards,

Sridhar

Former Member
0 Kudos

Hi Mukesh,

Thank you very much. Ir was very much helpfull

Regards

Maruti

Former Member
0 Kudos

Hi Sridhar,

Thank you very much. Ir was very much helpfull

Regards

Maruti

Answers (3)

Answers (3)

saraswathi_d
Participant
0 Kudos

Hi,

Check the below code

public static void wdDoModifyView(IPrivateDynamic_CompView wdThis, IPrivateDynamic_CompView.IContextNode wdContext, com.sap.tc.webdynpro.progmodel.api.IWDView view, boolean firstTime)

{

//@@begin wdDoModifyView

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

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

IWDAttributeInfo tabAttrib_Name = tabNode.addAttribute("contribution_area","ddic:com.sap.dictionary.string");

IWDAttributeInfo tabAttrib_Add = tabNode.addAttribute("SUM","ddic:com.sap.dictionary.string");

IWDTable tab = (IWDTable)view.createElement(IWDTable.class,"DynamicTabView");

IWDAttributeInfo attrib1 = tabNode.getAttribute("contribution_area");

IWDAttributeInfo attrib2 = tabNode.getAttribute("SUM");

tab.bindDataSource(tabNode);

tab.setCompatibilityMode(WDTableCompatibilityMode.AUTO);

tab.setDesign(WDTableDesign.ALTERNATING);

IWDTableColumn tabColumn1 = (IWDTableColumn)view.createElement(IWDTableColumn.class,"N_Co");

IWDTableColumn tabColumn2 = (IWDTableColumn)view.createElement(IWDTableColumn.class,"A_Co");

IWDInputField nameText = (IWDInputField)view.createElement(IWDInputField.class,"N_Text");

nameText.bindValue(attrib1);

tabColumn1.setTableCellEditor((IWDTableCellEditor)nameText);

IWDInputField addText = (IWDInputField)view.createElement(IWDInputField.class,"A_Text");

addText.bindValue(attrib2);

tabColumn2.setTableCellEditor((IWDTableCellEditor)addText);

tab.addColumn(tabColumn1);

tab.addColumn(tabColumn2);

tab.createLayoutData(IWDRowHeadData.class);

tab.setWidth("445");

rootElement.addChild(tab);

try

{

Connection con = wdThis.wdGetDynamic_CompController().Retrive();

Statement st=con.createStatement();

// ResultSet rs=st.executeQuery("Select * from test" );

ResultSet rs=st.executeQuery("SELECT contribution_table.contribution_area ,SUM(POINTS) from contribution_table where contribution_table.emp_id='Developer Developer' Group By contribution_area");

IWDNode dynNode=(IWDNode)wdContext.getChildNode("TabNode",0);

while(rs.next())

{

IWDNodeElement dynElem=(IWDNodeElement)dynNode.createElement();

//IWDNodeElement dynTabElem=(IWDNodeElement)dynTabNode.createElement();

dynElem.setAttributeValue("contribution_area",rs.getString(1));

dynElem.setAttributeValue("SUM",rs.getString(2));

dynNode.addElement(dynElem);

}

}

catch(Exception e)

{

e.printStackTrace();

}

//@@end

}

Code for oracle backend connection

public java.sql.Connection Retrive( )

{

//@@begin Retrive()

Connection conn=null;

try {

Class.forName("oracle.jdbc.driver.OracleDriver");

DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());

conn = DriverManager.getConnection("jdbc:oracle:thin:@10.6.2.197:1527:SMD","basis","install8");

} catch (Exception e) {

System.out.println(e);

}

return conn;

//@@end

}

Regards,

Saraswathi.

Pls reward points

Former Member
0 Kudos

Hi Saraswati,

Thank you very much. Your code was very much helpfull. But I had problems while modifing the data once polulated in table as its not allowing to modify the clild node already created. Any way thank you for help

Regards

Purna

Former Member
0 Kudos

hi maruti cr,

first u create the value node and add two value attributes to that node... and take ui element and bind value node to that table by right clicking the table ui and select create binding.

and write the code like this...

	
ArrayList al=new ArrayList();

IPrivate<Viewname>.I<node table>Element lobElement = wdContext.create<node table>Element();
lobElement.set<attribute1>(<value>);
lobElement.set<attribute2>(<value>);
  al.add(lobElement);
//repeat above four lines to create multiple rows. keep the above code in the for loop depending upon the rows u want to add..and finally bind that array list to node table.. as below out side the for loop.


		wdContext.node<node table>().bind(al);	

Former Member
0 Kudos

Hi Sunil,

Thank you very much, It was very much helpfull

Regards

Maruti

Former Member
0 Kudos

Read the <a href="https://www.sdn.sap.comhttp://www.sdn.sap.comhttp://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/docs/library/uuid/5f699f90-0201-0010-14a4-8950177281ed">Table Tutorial</a>.

Armin