on 03-08-2007 11:46 AM
Hi Experts,
I have the following context-structure in my WebDynpro-View (generated by WebService-Wizard):
+ Context
-----+ filterApps (0..n)
---------+ ResponseFilterApps (0..1)
---------------+ ResultFilterApps (0..n)
--------------------+ hwCompFilterApps (0..1)
--------------------+ swCompFilterApps (0..1)
-------------------------+ anwendungstitel (String)
-------------------------+ bezeichnung (String)
The cardinalities respectively datatypes are given in brackets (btw: I do not have any idea why the cardinality of "filterApps" is (0..n) - in other applications I have developped this is (0..1) - but does not seem to be a problem because the node's size() is 1).
After calling my WebService I receive 85 results, so the size() of node "ResultFilterApps" is as expected 85.
But traversing the node makes problems (see below). Here is my code:
IResultFilterAppsNode source = wdContext.nodeResultFilterApps();
System.err.println("size = " + source.size());
Iterator iter = source.iterateChildNodes();
int ix = 0;
while (iter.hasNext()) {
ISwCompFilterAppsNode myNode = (ISwCompFilterAppsNode)iter.next();
ix++;
System.err.println("accessing element " + ix);
}
This code results in following output:
size = 85
accessing element 1
Why does the iterator only contain 1 element instead of 85 elements?
Surprisingly I can call
myNode.getCurrentElement().getAttributeAsText("anwendungstitel");
This gives me the content of value attribute "anwendungstitel" of the first result delivered by my WebService.
Calling
myNode.getElementAt(0)
is ok, but calling
myNode.getElementAt(1)
leads to an IndexOutOfBoundsException.
What goes wrong? I am working with 2004s.
Thanks for every hint,
Christoph
(I assume that node swCompFilterApps is non-singleton, is that the case?)
IResultFilterAppsNode results = wdContext.nodeResultFilterApps();
for (int i = 0; i < results.size(); ++i)
{
IResultFilterAppsElement e = results.getResultFilterAppsElementAt(i);
IswCompFilterApps swNode = e.nodeswCompFilterApps();
if (swNode.size() > 0)
{
IswCompFilterAppsElement sw = swNode.getswCompFilterAppsElementAt(0);
String titel = sw.getAnwendungstitel();
String bez = sw.getBezeichnung();
}
}
Armin
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Armin,
thanks for trying to help. But it diesn't work.
IResultFilterAppsElement does not provide a method named "nodeSwCompFilterApps()". It only provides a method named "node()".
Method "getSwCompFilterAppsElementAt()" is undefined for class ISwCompFilterAppsNode, so I have to use
ISwCompFilterAppsElement sw = (ISwCompFilterAppsElement)swNode.getElementAt(0);
instead.
In summary I have to modify your code to the following:
IResultFilterAppsNode results = wdContext.nodeResultFilterApps();
for (int i = 0; i < results.size(); ++i)
{
IResultFilterAppsElement e = results.getResultFilterAppsElementAt(i);
ISwCompFilterAppsNode swNode = (ISwCompFilterAppsNode)e.node();
if (swNode.size() > 0)
{
//ISwCompFilterAppsElement sw = swNode.getswCompFilterAppsElementAt(0);
ISwCompFilterAppsElement sw = (ISwCompFilterAppsElement)swNode.getElementAt(0);
String titel = sw.getAnwendungstitel();
String bez = sw.getBezeichnung();
}
}
This leads to a ClassCastException performinng the statement
ISwCompFilterAppsNode swNode = (ISwCompFilterAppsNode)e.node();
Regards,
Christoph
Is node swCompFilterApps non-singleton? (That was my assumption.)
Is "typedAccessRequired" set to true?
Your modification to my code is wrong. The node() method gives you the <b>containing </b>node for a node element, the node<Subnode>() gives you the (non-singleton) <b>subnode </b>for a node element.
Armin
Hi Monalisa,
how could I do this? The node was originally created by the wizard that imports a WebService into my WD-model. The wizard defined the cardinality in the model and I cannotr change this. Mapping the node from model to controller effects that the generated context-node has the same cardinality. Cardinality of the context-node cannot be changed because it is mapped from the model.
Regards,
Christoph
Ok, I've got a suitable solution for me. I still do not understand why iterateChildNodes does not work as I think it should work Obviously there is something I do not understand. But here's my solution for iterating child nodes (even if I know that I am moving in model with this solution and not in the view's context):
IResultFilterAppsElement elem;
int resCnt;
IResultFilterAppsNode source = wdContext.nodeResultFilterApps();
resCnt = source.size();
System.err.println("size = " + source.size());
for (int ix=0; ix<resCnt; ix++) {
elem = source.getResultFilterAppsElementAt(ix);
System.err.println("Titel " + ix + ": " + elem.modelObject().getSwComp().getAnwendungstitel());
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Christoph,
Either you are posting incomplete/modified code or your code is totaly broken.
You are iterating over node ResultFilterApps but getting elements swCompFilterApps from iterator. In reality your app should print size (85) and then fail with class cast exception.
Additional hint: make sure that swCompFilterApps is not a singleton.
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 Valery,
in fact it's right: I get the output "size = 85". But I do not get any ClassCastException.
Concerning your hint to the cardinality of swCompFilterApps: I think that this is in fact the problem. But as I already answered to Monalisa:
"How could I set the cardinality to "0..n"? The node was originally created by the wizard that imports a WebService into my WD-model. The wizard defined the cardinality in the model and I cannotr change this. Mapping the node from model to controller effects that the generated context-node has the same cardinality. Cardinality of the context-node cannot be changed because it is mapped from the model."
Any more idea?
Regards,
Christoph
Christoph,
You always can change cardinality of root model node to 0..1. Also you may change singleton/non-singleton property of node in question. Just edit context of component controller (rather then view context).
Valery Silaev
SaM Solutions
Hi,
Try this, it will help u
int size=wdcontext.nodeResultFileterApps().size();
int counter=0;
for(int i=0;i<size;i++)
{
IResultFilterAppsNode source = wdContext.nodeResultFilterApps().getResultFilterAppsElementAt(i);
System.err.println("size = " + source.size());
Iterator iter = source.iterateChildNodes();
int ix = 0;
while (iter.hasNext()) {
ISwCompFilterAppsNode myNode = (ISwCompFilterAppsNode)iter.next();
ix++;
System.err.println("accessing element " + ix);
}
System.err.println("counter: " + counter);
counter++;
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Christiph,
Try using,
IResultFilterAppsNode source = wdContext.nodeResultFilterApps();
System.err.println("size = " + source.size());
For(int i =0 ; i<source.size() ; i++)
{
IResultFilterAppsElement ele = source.getResultFilterElementAt(i);
wdComponentAPI.getMessageManager().reportSuccess("Accessing Element: " + i);
}
Hope this helps.
Regards,
Mausam
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Mausam,
thank you for help. In fact I receive 85 outputs as expected. But how can I access the 85 elements? I tried the following:
System.err.println("titel " + i + " : " + ele.getAttributeAsText("anwendungstitel"));
Result is a NullPointerException in getAttributeAsText()
System.err.println("titel " + i + " : " + ele.getAttributePointer("anwendungstitel"));
Result is an IllegalArgumentException in getAttributePointer (No such attribute anwendungstitel)
System.err.println("titel " + i + " : " + ele.getAttributePointer("swCompFilterApps"));
Result is an IllegalArgumentException in getAttributePointer (No such attribute swCompFilterApps)
Any more ideas?
Regards,
Christoph
Hi Christiph,
Try using,
IResultFilterAppsNode source = wdContext.nodeResultFilterApps();
System.err.println("size = " + source.size());
For(int i =0 ; i<source.size() ; i++)
{
IResultFilterAppsElement ele = source.getResultFilterElementAt(i);
wdComponentAPI.getMessageManager().reportSuccess("Accessing Element: " + i);
}
Here, "ele" in the For loop is your required element at "i".
You can go through all the methods of "ele", like for getting your "titel", you can use "ele.getTitel()" method. Same for the other attributes.
Hope this helps.
Regards,
Mausam>
Hi Mausam,
sorry for my late answer. "ele" does not provide any methods like "getTitle()". It only provides methods like "getAttributeValue()", "getAttributeAsText()", "getAttributePointer()". The problem seems to be that under my node "ResultFilterApps" there are two other nodes ("hwCompFilterApps" and "swCompFilterApps"). The real attributes are located under these nodes. How can I access the nodes "hwCompFilterApps" and "swCompFilterApps" or the attributes under these nodes?
Regards,
Christoph
IterateChildNode does not iterate through elements , it helps in iterating child nodes of the node.To access elements of the node
int size =wdContext.node<NodeName>().size();
for(int i=0;i<size;i++)
{
msgMgr.reportSuccess(
wdContext.node<NodeName>().getElementAt(i).getAttributeAsText("<attributeName>");
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
85 | |
10 | |
10 | |
10 | |
7 | |
6 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.