cancel
Showing results for 
Search instead for 
Did you mean: 

Dynamic Table creation

Former Member
0 Kudos

Hi,

I was trying to take number of fields from a context node dynamically. But after executing the code I am getting the number of fields as null. Can anyone tell me what is wrong with my code?

This is the code fragment:-

IWDNodeInfo tabNode = wdContext.nodeName().getNodeInfo();

IStructure structure = tabNode.getStructureType();

int NoOfFlds =(int)structure.getNumberOfFields();

Thanks in advance,

Indu

Accepted Solutions (0)

Answers (5)

Answers (5)

monalisa_biswal
Contributor
0 Kudos

I think u have not binded ur node to a structure.Thats why it is returning null

Try to use following method

IWDNodeInfo nodeInfo = wdContext.nodeName().getNodeInfo();

Iterator it = nodeInfo.iterateAttributes();

while( it.hasNext() )

{

IWDAttributeInfo attrInfo = (IWDAttributeInfo) it.next();

String attributeName = attrInfo.getName();

}

Hope it helps.

Former Member
0 Kudos

Indu,

Strictly speaking, you are not getting null as number of fields, but rather get NullPointerException on line:

int NoOfFlds =(int)structure.getNumberOfFields();

WD nodes may or may not have structure binding. Also this is not stated explicitly, the nodes with structure binding are typically nodes that created over Adaptive RFC Model classes (though you can create your own structure types in DDIC project, or when you are creating CAF Services).

Due to this dualism, you have to check whether or not node has structure type and either get number of fields directly, or iterate attributes in loop and calculate count (as suggested by R.Knibbe in this thread):


final IWDNodeInfo tabNode = wdContext.nodeName().getNodeInfo(); 
final IStructure structure = tabNode.getStructureType();
int NoOfFlds = 0;
if (null != structure)
  NoOfFlds = structure.getNumberOfFields();
else
  for (final Iterator i = tabNode.iterateAttributes(); i.hasNext(); i.next() ) 
    NoOfFields++;

Valery Silaev

SaM Solutions

http://www.sam-solutions.net

Former Member
0 Kudos

Hi,

Your code is perfectly fine, can you post ur context structure. And typecasting to int is not required as getNumberOfFields() returns int value only.

You said that its giving null, if u r displaying NoOfFilds, there is no point of getting null because an int variable cannot hold null.

Try displaying the NoOfFilds using a message.

IWDMessageManager msg = wdComponentAPI.getMessageManager();

msg.reportSuccess("No of fields"+NoOfFilds);

Please let us know what's it displaying.

Regards,

Aparna .P

Former Member
0 Kudos

My context structure is:-

name- value node

under this there are 3 value attribute:- name,place,phone.All are of type String.

We tried to print no of nodes as u said, but nothing has been displayed.

Can u please tell me what is wrong with my code?

Indu

monalisa_biswal
Contributor
0 Kudos

U can go thrugh this thread.

Former Member
0 Kudos

Hi,

Context attributes are not necessarily part of a structure.

I would use wdContext.nodeName().getNodeInfo().iterateAttributes()

and count the attributes myself inside a while loop.

Maybe a bit awkward but I don't know an easier way.

Good luck,

Roelof