cancel
Showing results for 
Search instead for 
Did you mean: 

Create Table Columns Dynamically

Former Member
0 Kudos

Hi All,

I need to create a table column dynamically based on values in a node. If the node has 3 rows populated then I would need to create 3 columns corresponding to these 3 rows and with values contained in each row of the node.

Can someone tell me as to how I go about doing this.

Thanks in advance.

Best regards,

Divya

Accepted Solutions (0)

Answers (4)

Answers (4)

Former Member
0 Kudos

divya,

i dont think so that you have getAttributeInfo for a node in context.

and more over you cant cast attribute info to node info

regards

jk

Former Member
0 Kudos

Hi All,

Then can someone tell me as to how I can create a table column dynamically and assign a value to its TableCellEditor of type Text View.

Thanks in advance.

Best regards,

Divya

Former Member
0 Kudos

what error ru getting

Former Member
0 Kudos

Hi Karthikeyan,

This is the error.

java.lang.IndexOutOfBoundsException: Index: 1, Size: 0

at java.util.ArrayList.add(ArrayList.java:371)

at com.sap.tc.webdynpro.progmodel.context.Node$ElementList.addElementSilently(Node.java:2045)

at com.sap.tc.webdynpro.progmodel.context.Node$ElementList.addElement(Node.java:2057)

at com.sap.tc.webdynpro.progmodel.context.Node.doAddElement(Node.java:726)

at com.sap.tc.webdynpro.progmodel.context.Node.addElement(Node.java:694)

at com.accenture.pct.hpb.HPBCustomerLoanCompSimulations.wdDoModifyView(HPBCustomerLoanCompSimulations.java:210)

at com.accenture.pct.hpb.wdp.InternalHPBCustomerLoanCompSimulations.wdDoModifyView(InternalHPBCustomerLoanCompSimulations.java:355)

at com.sap.tc.webdynpro.progmodel.generation.DelegatingView.doModifyView(DelegatingView.java:78)

at com.sap.tc.webdynpro.progmodel.view.View.modifyView(View.java:190)

at com.sap.tc.webdynpro.clientserver.cal.ClientComponent.doModifyView(ClientComponent.java:397)

at com.sap.tc.webdynpro.clientserver.cal.ClientComponent.doModifyView(ClientComponent.java:404)

at com.sap.tc.webdynpro.clientserver.cal.ClientApplication.modifyView(ClientApplication.java:613)

at com.sap.tc.webdynpro.clientserver.task.WebDynproMainTask.handleActionEvent(WebDynproMainTask.java:372)

at com.sap.tc.webdynpro.clientserver.task.WebDynproMainTask.execute(WebDynproMainTask.java:640)

at com.sap.tc.webdynpro.clientserver.cal.AbstractClient.executeTasks(AbstractClient.java:59)

at com.sap.tc.webdynpro.clientserver.cal.ClientManager.doProcessing(ClientManager.java:251)

at com.sap.tc.webdynpro.serverimpl.defaultimpl.DispatcherServlet.doWebDynproProcessing(DispatcherServlet.java:154)

at com.sap.tc.webdynpro.serverimpl.defaultimpl.DispatcherServlet.doContent(DispatcherServlet.java:116)

at com.sap.tc.webdynpro.serverimpl.defaultimpl.DispatcherServlet.doPost(DispatcherServlet.java:55)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)

at com.sap.engine.services.servlets_jsp.server.HttpHandlerImpl.runServlet(HttpHandlerImpl.java:391)

at com.sap.engine.services.servlets_jsp.server.HttpHandlerImpl.handleRequest(HttpHandlerImpl.java:265)

at com.sap.engine.services.httpserver.server.RequestAnalizer.startServlet(RequestAnalizer.java:345)

at com.sap.engine.services.httpserver.server.RequestAnalizer.startServlet(RequestAnalizer.java:323)

at com.sap.engine.services.httpserver.server.RequestAnalizer.invokeWebContainer(RequestAnalizer.java:865)

at com.sap.engine.services.httpserver.server.RequestAnalizer.handle(RequestAnalizer.java:240)

at com.sap.engine.services.httpserver.server.Client.handle(Client.java:92)

at com.sap.engine.services.httpserver.server.Processor.request(Processor.java:148)

at com.sap.engine.core.service630.context.cluster.session.ApplicationSessionMessageListener.process(ApplicationSessionMessageListener.java:37)

at com.sap.engine.core.cluster.impl6.session.UnorderedChannel$MessageRunner.run(UnorderedChannel.java:71)

at com.sap.engine.core.thread.impl3.ActionObject.run(ActionObject.java:37)

at java.security.AccessController.doPrivileged(Native Method)

at com.sap.engine.core.thread.impl3.SingleThread.execute(SingleThread.java:94)

at com.sap.engine.core.thread.impl3.SingleThread.run(SingleThread.java:162)

This my code:

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

IPrivateHPBCustomerLoanCompSimulations.IDsSimulationCompElement dsSimEle = wdContext.nodeDsSimulationComp().getDsSimulationCompElementAt(i);

for(int j=1; j<14; j++){

if(j==1){

IPrivateHPBCustomerLoanCompSimulations.IColumn1Element col1 = wdContext.nodeColumn1().createColumn1Element();

col1.setDESCRIPTION(Double.toString(dsSimEle.getAMT()));

wdContext.nodeColumn1().addElement(j,col1);

}

if(j==2){

IPrivateHPBCustomerLoanCompSimulations.IColumn1Element col1 = wdContext.nodeColumn1().createColumn1Element();

col1.setDESCRIPTION(Integer.toString(dsSimEle.getNUM()));

wdContext.nodeColumn1().addElement(j,col1);

}

if(j==3){

IPrivateHPBCustomerLoanCompSimulations.IColumn1Element col1 = wdContext.nodeColumn1().createColumn1Element();

col1.setDESCRIPTION("");

wdContext.nodeColumn1().addElement(j,col1);

}

if(j==4){

IPrivateHPBCustomerLoanCompSimulations.IColumn1Element col1 = wdContext.nodeColumn1().createColumn1Element();

col1.setDESCRIPTION("");

wdContext.nodeColumn1().addElement(j,col1);

}

if(j==5){

IPrivateHPBCustomerLoanCompSimulations.IColumn1Element col1 = wdContext.nodeColumn1().createColumn1Element();

col1.setDESCRIPTION("");

wdContext.nodeColumn1().addElement(j,col1);

}

if(j==6){

IPrivateHPBCustomerLoanCompSimulations.IColumn1Element col1 = wdContext.nodeColumn1().createColumn1Element();

col1.setDESCRIPTION("");

wdContext.nodeColumn1().addElement(j,col1);

}

if(j==7){

IPrivateHPBCustomerLoanCompSimulations.IColumn1Element col1 = wdContext.nodeColumn1().createColumn1Element();

col1.setDESCRIPTION("");

wdContext.nodeColumn1().addElement(j,col1);

}

if(j==8){

IPrivateHPBCustomerLoanCompSimulations.IColumn1Element col1 = wdContext.nodeColumn1().createColumn1Element();

col1.setDESCRIPTION("");

wdContext.nodeColumn1().addElement(j,col1);

}

if(j==9){

IPrivateHPBCustomerLoanCompSimulations.IColumn1Element col1 = wdContext.nodeColumn1().createColumn1Element();

col1.setDESCRIPTION("");

wdContext.nodeColumn1().addElement(j,col1);

}

if(j==10){

IPrivateHPBCustomerLoanCompSimulations.IColumn1Element col1 = wdContext.nodeColumn1().createColumn1Element();

col1.setDESCRIPTION("");

wdContext.nodeColumn1().addElement(j,col1);

}

if(j==11){

IPrivateHPBCustomerLoanCompSimulations.IColumn1Element col1 = wdContext.nodeColumn1().createColumn1Element();

col1.setDESCRIPTION("");

wdContext.nodeColumn1().addElement(j,col1);

}

if(j==12){

IPrivateHPBCustomerLoanCompSimulations.IColumn1Element col1 = wdContext.nodeColumn1().createColumn1Element();

col1.setDESCRIPTION("");

wdContext.nodeColumn1().addElement(j,col1);

}

if(j==13){

IPrivateHPBCustomerLoanCompSimulations.IColumn1Element col1 = wdContext.nodeColumn1().createColumn1Element();

col1.setDESCRIPTION("");

wdContext.nodeColumn1().addElement(j,col1);

}

}

IWDTable tblCompSim = (IWDTable)view.getElement("tblCompSim");

String colName = "Sim" + Integer.toString(i);

IWDTableColumn colComp = (IWDTableColumn)view.createElement(IWDTableColumn.class,colName);

String colHead = "ColHeader" + Integer.toString(i);

IWDCaption colHeader = (IWDCaption)view.createElement(IWDCaption.class,colHead);

String colText = "Simulation" + Integer.toString(i);;

colHeader.setText(colText);

colComp.setHeader(colHeader);

String nameView = "NameViewer" + Integer.toString(i);

IWDTextView nameViewer = (IWDTextView) view.createElement(IWDTextView.class,nameView);

IWDAttributeInfo attInfo = (IWDAttributeInfo)wdContext.nodeColumn1().getContext();

nameViewer.bindText(attInfo);

IWDTableCellEditor tblEditor = (IWDTableCellEditor)nameViewer;

colComp.setTableCellEditor(tblEditor);

tblCompSim.addColumn(colComp);

}

Thanks in advance,

Best regards,

Divya

Former Member
0 Kudos

Divya,

Quite unclear:

You are using node elements for table metadata, i.e. for columns. What node elements will be used for data, i.e. table rows???

VS

Former Member
0 Kudos

Hi Divya,

The solution could be like this

1. iterate through the node collection and find the number of rows present in the node

1.1. for each of the row in the node, create a context element for each of the row in the node

1.2. for each of the iteration, create table coulums and add it to the table, and bind corresponding created context element to the corresponding column.

think this will work out

regards

karthikeyan j

Former Member
0 Kudos

Hi Karthikeyan,

This what I have exactly done. But when I bind I get an exception.

Where could I be wrong?

Best regards,

Divya

Former Member
0 Kudos

Your question is not clear.

As noted by Valery, you speak of some data structure (context node) for storing the table structure but you said nothing about where the resulting table should get its data.

Armin

Former Member
0 Kudos

Hi Armin,

I have node nodeDsSimulationComp if this has 3 Rows and fixed 14 Columns then I need to create a resulting table which has fixed 14 rows with 3 columns. Each of these columns is bound to a context node nodeColumn1 which will contain the 14 values.

To be more precise I need to convert a table of x rows and y columns to a table of y rows and x columns.

Thanks in advance.

Best regards,

Divya

Former Member
0 Kudos

Hi Karthikeyan,

I solved the out of bounds exception. Now I get a new exception which is enclosed below:

java.lang.ClassCastException

at com.accenture.pct.hpb.HPBCustomerLoanCompSimulations.wdDoModifyView(HPBCustomerLoanCompSimulations.java:307)

at com.accenture.pct.hpb.wdp.InternalHPBCustomerLoanCompSimulations.wdDoModifyView(InternalHPBCustomerLoanCompSimulations.java:355)

at com.sap.tc.webdynpro.progmodel.generation.DelegatingView.doModifyView(DelegatingView.java:78)

at com.sap.tc.webdynpro.progmodel.view.View.modifyView(View.java:190)

at com.sap.tc.webdynpro.clientserver.cal.ClientComponent.doModifyView(ClientComponent.java:397)

at com.sap.tc.webdynpro.clientserver.cal.ClientComponent.doModifyView(ClientComponent.java:404)

at com.sap.tc.webdynpro.clientserver.cal.ClientApplication.modifyView(ClientApplication.java:613)

at com.sap.tc.webdynpro.clientserver.task.WebDynproMainTask.handleActionEvent(WebDynproMainTask.java:372)

at com.sap.tc.webdynpro.clientserver.task.WebDynproMainTask.execute(WebDynproMainTask.java:640)

at com.sap.tc.webdynpro.clientserver.cal.AbstractClient.executeTasks(AbstractClient.java:59)

at com.sap.tc.webdynpro.clientserver.cal.ClientManager.doProcessing(ClientManager.java:251)

at com.sap.tc.webdynpro.serverimpl.defaultimpl.DispatcherServlet.doWebDynproProcessing(DispatcherServlet.java:154)

at com.sap.tc.webdynpro.serverimpl.defaultimpl.DispatcherServlet.doContent(DispatcherServlet.java:116)

at com.sap.tc.webdynpro.serverimpl.defaultimpl.DispatcherServlet.doPost(DispatcherServlet.java:55)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)

at com.sap.engine.services.servlets_jsp.server.HttpHandlerImpl.runServlet(HttpHandlerImpl.java:391)

at com.sap.engine.services.servlets_jsp.server.HttpHandlerImpl.handleRequest(HttpHandlerImpl.java:265)

at com.sap.engine.services.httpserver.server.RequestAnalizer.startServlet(RequestAnalizer.java:345)

at com.sap.engine.services.httpserver.server.RequestAnalizer.startServlet(RequestAnalizer.java:323)

at com.sap.engine.services.httpserver.server.RequestAnalizer.invokeWebContainer(RequestAnalizer.java:865)

at com.sap.engine.services.httpserver.server.RequestAnalizer.handle(RequestAnalizer.java:240)

at com.sap.engine.services.httpserver.server.Client.handle(Client.java:92)

at com.sap.engine.services.httpserver.server.Processor.request(Processor.java:148)

at com.sap.engine.core.service630.context.cluster.session.ApplicationSessionMessageListener.process(ApplicationSessionMessageListener.java:37)

at com.sap.engine.core.cluster.impl6.session.UnorderedChannel$MessageRunner.run(UnorderedChannel.java:71)

at com.sap.engine.core.thread.impl3.ActionObject.run(ActionObject.java:37)

at java.security.AccessController.doPrivileged(Native Method)

at com.sap.engine.core.thread.impl3.SingleThread.execute(SingleThread.java:94)

at com.sap.engine.core.thread.impl3.SingleThread.run(SingleThread.java:162)

It occurs when I type cast this line:

IWDAttributeInfo attInfo = (IWDAttributeInfo)wdContext.nodeColumn1().getContext();

nameViewer.bindText(attInfo);

Can anyone tell me why?

Best regards,

Divya

Former Member
0 Kudos

Ok, you want to transpose a matrix.

You can do that by dynamically creating context attributes.

Let T be the original table, T' be the transposed table, and assume both tables have data source nodes assigned.

foreach node element e in T.dataSource
  add attribute A(e) to T'.dataSource
end

The type of each attribute A(e) may depend on some attribute value of node element e.

Now you have to fill T'.dataSource with node elements where the attribute values are taken from the original table's data source.

Finally create the structure of the transposed table:

foreach attribute A of T'.dataSource
  C = new TableColumn
  E = new TextView
  E.bindText(A)
  C.setTableCellEditor(E)
  T'.addColumn(C)
end

Your task now ist to translate this into the Web Dynpro API.

Armin

Former Member
0 Kudos

Hi Armin,

This is exactly what I am doing. But I get an error when I try to bind it to the text View.Am sure the problem occurs when I try to bind text to the text View. Enclosed below is a sample where am trying to create to table columns dynamically with 14 rows and this fails.

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

for(int j=1; j<14; j++){

IPrivateHPBCustomerLoanCompSimulations.IDsSimDescElement ele = wdContext.nodeDsSimDesc().createDsSimDescElement();

if(j==1){

ele.setDESCRIPTION(Integer.toString(j));

}

if(j==2){

ele.setDESCRIPTION(Integer.toString(j));

}

if(j==3){

ele.setDESCRIPTION(Integer.toString(j));

}

if(j==4){

ele.setDESCRIPTION(Integer.toString(j));

}

if(j==5){

ele.setDESCRIPTION(Integer.toString(j));

}

if(j==6){

ele.setDESCRIPTION(Integer.toString(j));

}

if(j==7){

ele.setDESCRIPTION(Integer.toString(j));

}

if(j==8){

ele.setDESCRIPTION(Integer.toString(j));

}

if(j==9){

ele.setDESCRIPTION(Integer.toString(j));

}

if(j==10){

ele.setDESCRIPTION(Integer.toString(j));

}

if(j==11){

ele.setDESCRIPTION(Integer.toString(j));

}

if(j==12){

ele.setDESCRIPTION(Integer.toString(j));

}

if(j==13){

ele.setDESCRIPTION(Integer.toString(j));

}

wdContext.nodeDsSimDesc().addElement(ele);

}

IWDTable tblCompSim = (IWDTable)view.getElement("tblCompSim");

String colName = "Sim" + Integer.toString(i);

IWDTableColumn colComp = (IWDTableColumn)view.createElement(IWDTableColumn.class,colName);

String colHead = "ColHeader" + Integer.toString(i);

IWDCaption colHeader = (IWDCaption)view.createElement(IWDCaption.class,colHead);

String colText = "Simulation" + Integer.toString(i);;

colHeader.setText(colText);

colComp.setHeader(colHeader);

String nameView = "NameViewer" + Integer.toString(i);

IWDTextView nameViewer = (IWDTextView) view.createElement(IWDTextView.class,nameView);

nameViewer.bindText(wdThis.wdGetContext().currentDsSimDescElement().getDESCRIPTION());

IWDTableCellEditor tblEditor = (IWDTableCellEditor)nameViewer;

colComp.setTableCellEditor(tblEditor);

tblCompSim.addColumn(colComp);

Where could I be going wrong??

Thanks in advance.

Regards,

Divya

Former Member
0 Kudos

Apart from all these if's (what are they good for?):

nameViewer.bindText(wdThis.wdGetContext().currentDsSimDescElement().getDESCRIPTION());

This line makes no sense.

Method bind<property>(<context attribute info>) is used to <b>bind </b>a UI element property to a view context attribute. This means, the property's storage area will become the context attribute.

In your example, you pass a context attribute <b>value</b> to the bind method.

Did you try to translate my pseudo-code into Web Dynpro API?

Armin

Former Member
0 Kudos

Hi Armin,

Well... those ifs were just fillers as I cant post actual code due to Confidential info. I bound the attribute info property to the UI Element and it works fine.Thats where like I said earlier as well was the problem.

IWDAttributeInfo attInfo = wdContext.getChildNode("dsSimDesc",IWDNode.LEAD_SELECTION).getNodeInfo().getAttribute("DESCRIPTION");

nameViewer.bindText(attInfo);

I just needed some additional help for some other logic. I have a node nodeDsSimDesc and I want to create child nodes/attributes within it dynamically and tie that to the dynamically created columns. Can you tell me a way I could do so.

Thanks in advance.

Best regards,

Divya