cancel
Showing results for 
Search instead for 
Did you mean: 

Dynamic Context Mapping Issue

Former Member
0 Kudos

Hi All,

Im creating an application which retrieves some records from a database. I have written this code in the component controller. I have created a dynamic node and attributes here and set their values to the data from the database. Then I have mapped the node and the attributes dynamically to the view controller. The node in the view context is then bound to a dynamic table which displays the records. Pls see the code as given below,

<u><b>Component Controller:</b></u>

public void Retrive( )

{

//@@begin Retrive()

Connection conn=null;

ResultSet rs = null;

Statement st = null;

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

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

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

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");

st=conn.createStatement();

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

// 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("ComTabNode",0);

while(rs.next())

{

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

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

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

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

dynNode.addElement(dynElem);

}

}

catch(Exception e)

{

e.printStackTrace();

}

}

<u><b>View Controller:</b></u>

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().addMappedChild("ViewTabNode",null,true,true,false,null,false,true);

IWDNodeInfo comp_node_info = wdThis.wdGetDynamic_CompController().wdGetContext().getNodeInfo().getChild("ComTabNode");

tabNode.setMapping(comp_node_info,true);

IWDAttributeInfo info = tabNode.addMappedAttribute("contribution_area",".Dynamic_Comp.ComTabNode.contribution1_area");

IWDAttributeInfo info1 = tabNode.addMappedAttribute("SUM",".Dynamic_Comp.ComTabNode.SUM1");

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);

tab.setVisibleRowCount(10);

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

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

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);

IWDCaption caption2 =

(IWDCaption) view.createElement(IWDCaption. class , "cap2" );

caption2.setText( "Contribution Area" );

tabColumn2.setHeader(caption2);

IWDCaption sumCap=(IWDCaption)view.createElement(IWDCaption.class,"sumCap");

sumCap.setText("SUM");

tabColumn2.setHeader((IWDCaption)sumCap);

tab.addColumn(tabColumn1);

tab.addColumn(tabColumn2);

tab.createLayoutData(IWDRowHeadData.class);

tab.setWidth("445");

rootElement.addChild(tab);

}

I call the method retrive() in the wdDoInit() of the view controller.

The problem that Im facing is, I get only the first record in the table.

Can anyone help?

Regards,

Suman

Message was edited by: suman sahu

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi all,

I solved it by my own.There was some problem in cardinality.

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

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

The cardinality should be true.

Suman

Former Member
0 Kudos

Suman,

Actually, your phrase have to be "The cardinality should be <b>multiple</b>"

Interesting, you may not trap into this error at design-time, i.e. context designer track cases when you create one-element node mapped to multiple node (and prevents you from doing this). As your error shows it's ok at run-time: only lead selected element will be displayed.

Valery Silaev

SaM Solutions

http://www.sam-solutions.net

Former Member
0 Kudos

Hi Suman,

The following needs to be corrected in your view controller.

WDCaption sumCap=(IWDCaption)view.createElement(IWDCaption.class,"sumCap");

sumCap.setText("SUM");

tabColumn2.setHeader((IWDCaption)sumCap);

IWDCaption sumCap2 = (IWDCaption)view.createElement(IWDCaption.class,"sumCap2");

sumCap2.setText("SUM");

tabColumn2.setHeader(sumCap2);

You can't declare two variables with same name and you can't create two UIElements with sameID.

Make sure that your resultset return morethan 2 records.

Reagrds, Anilkumar

Former Member
0 Kudos

Hi Anil,

I did mistake there.Now I have changed it.That is not the problem .So any other idea u have can u please let me know.

Suman