cancel
Showing results for 
Search instead for 
Did you mean: 

Action handling of dynamically created button inside a table

Former Member
0 Kudos

Can anyone tell me how to handle the node element of a row in a table which has dynamically created buttons.

here is the snippet of code written-:

-


//tableItemNodeInfo = "TableItemDisplayFields" node

resultSetTable.bindDataSource(tableItemNodeInfo);

IWDTableColumn tabColumn = (IWDTableColumn)

view.createElement(IWDTableColumn.class,SHOPPING_CART);

IWDCaption caption = (IWDCaption)view.createElement(IWDCaption.class,

"ShoppingCart");

caption.setText("Action");

tabColumn.setHeader(caption);

/* content of the column */

IWDButton colButton = (IWDButton)

view.createElement(IWDButton.class,"ShoppingCartButton");

IWDAttributeInfo attributeInfo = (IWDAttributeInfo)

tableItemNodeInfo.getAttribute("SHOPPING_CART");

colButton.setEnabled(true);

colButton.setImageSource(SHOPPING_CART_IMG);

colButton.setWidth(FIXED_COL_WIDTH);

// Action defined at design time

IWDAction shoppingCartAction =

wdThis.wdGetAddToShoppingCartAction();

colButton.setOnAction(shoppingCartAction)

// "TableItemDisplayFields" is the node created at runtime.

colButton.mappingOfOnAction().addParameter("nodeElement","TableItemDisplayFields");

tabColumn.setTableCellEditor(colButton);

resultSetTable.addColumn(tabColumn);

public void onActionaddToShoppingCart(com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent, com.sap.tc.webdynpro.progmodel.api.IWDNodeElement nodeElement )

{

//@@begin onActionaddToShoppingCart(ServerEvent)

wdComponentAPI.getMessageManager().reportSuccess("Done" +

nodeElement.getClass());

//@@end

}

-


I get java.lang.ArrayIndexOutOfBoundsException exception when i click any of the dynamically created button present in the table.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Armin,

I have already tried something like this as mentioned below -:

colButton.mappingOfOnAction().addParameter("nodeElement", "element");

public void onActionaddToShoppingCart(com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent, com.sap.tc.webdynpro.progmodel.api.IWDNodeElement element )

{

//@@begin onActionaddToShoppingCart(ServerEvent)

wdComponentAPI.getMessageManager().reportSuccess("Done" +

element.getClass());

//@@end

}

I get a java.lang.NullPointerException at runtime when I press the button.

One more thing I didnt bind any property of the button with the "element" node type. Do you think this could be an issue. I can not try this out right now as I have some problem with my J2EE server.

Former Member
0 Kudos

Instead of

colButton.mappingOfOnAction().addParameter("nodeElement", "element");

use

colButton.mappingOfOnAction().addSourceMapping("nodeElement", "element");

Armin

Former Member
0 Kudos

Hello Armin,

In my application I have a value node "abcValue" for which I have created a Table. It has got a button in it . In the wdDoModifyView method I have written a code

if(firstTime)

{

IWDButton button = (IWDButton) view.getElement("deleteButton");

button.mappingOfOnAction().addSourceMapping

( "nodeElement", // name of implicit event parameter

"toDeleteElement" // name of action parameter

);

}

and on Action of teh button

I have passed the "abcValueElement" .

after which I have written a code

abcValueElement.node().remove(abcValueElement) up on which I am getting classCastException.

Please can you suggest me whether I am doing in a right way.

Thanks in advance.

V Vinay

former_member286976
Active Participant
0 Kudos

Hello Vinay,

In the below code, the second parameter name of the function is 'toDeleteElement'

button.mappingOfOnAction().addSourceMapping
( "nodeElement", // name of implicit event parameter
"toDeleteElement" // name of action parameter
);

You should use the same parameter name in ur action handling function. Change the parameter name of IWDNodeElement type from 'abcValueElement' to 'toDeleteElement'.

Regards,

Sudeep.

Answers (4)

Answers (4)

Former Member
0 Kudos

Hai,

I did the same application what you mentioned above , bu i did in dynpro by static.

steps:

1) create a table then in side the Column (whch you want to put buuton) select button as the table cell editor. created an action clickButton() , bind this action to button.

2) write the code inside the clickButton()as to read the data of the current selected node.

3) process the logic which you want to do with the selected node in the table.

regards,

Naga Raju

Former Member
0 Kudos

If you are binding your table to a node then you can have a button as a table cell in the button column. To the button onAction event you can bind the static action. If a button is pressed the leadselection should return the row number.

Former Member
0 Kudos

Replace

colButton.mappingOfOnAction().addParameter("nodeElement","TableItemDisplayFields");

by

colButton.mappingOfOnAction().addSourceMapping
(
  "nodeElement",
  "nodeElement" /* name of action parameter */
);

Armin

Former Member
0 Kudos

Paritosh,

Code looks ok to me. Howevere I'm wondering why not to use IDE designer instead of dynamic programming here (besides parameter mapping, of course)?

Just make sure that you set "compatability mode" on Table itself to NW04s. Also it is probably necessary to bind button's "text" to some attribute of tableItemNodeInfo.

VS

Former Member
0 Kudos

Hi Valery,

Thanks for the quick response but both the solution did not work out for me.

I need to create the node dynamically as the table columns are configurable.

Can you tell me some other way of knowing which button coresponds to which row in the table (The node is created dynamically so I can not use addParameter(String name, int value) )

Toush

Former Member
0 Kudos

Paritosh,

Read reply by Armin -- this is the answer.

VS