on 12-01-2006 10:17 AM
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
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
81 | |
9 | |
9 | |
7 | |
7 | |
6 | |
6 | |
6 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.