Skip to Content
avatar image
Former Member

Problem when iterating a context-node

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

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

6 Answers

  • Best Answer
    avatar image
    Former Member
    Mar 08, 2007 at 02:07 PM

    (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

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member Monalisa Biswal

      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

  • avatar image
    Former Member
    Mar 21, 2007 at 11:22 AM

    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

    http://www.sam-solutions.net

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member Former Member

      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

      http://www.sam-solutions.net

  • Mar 08, 2007 at 12:27 PM

    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>");

    }

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member

      Hi Monalisa,

      thanks for trying to help. But it doesn't work. It results in a NullPointerException in getAttributeAsText(). I tried with <attributeName> "anwendungstitel" and "swCompFilterApps".

      Do you have any more ideas?

      Regards,

      Christoph

  • avatar image
    Former Member
    Mar 08, 2007 at 12:29 PM

    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

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member Former Member

      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

  • avatar image
    Former Member
    Mar 08, 2007 at 12:56 PM

    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++;

    }

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member

      Hi Siva,

      sorry, this can't work. getResultFilterAppsElementAt() delivers IResultFilterAppsElement, not IResultFilterAppsNode as in your suggested code. And IResultFilterAppsElement does not know methods "size()" and "iterateChildNodes()".

      Thanks for trying to help,

      Christoph

  • avatar image
    Former Member
    Mar 22, 2007 at 07:42 AM

    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());
    }
    

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member

      Christoph,

      The same should work as well if ResultFilterApps and swComp is non-singleton nodes and swComp has initializeLeadSelection=true:

      System.err.println("Titel " + ix + ": " + elem.currentSwCompElement().getAnwendungstitel());
      

      VS