cancel
Showing results for 
Search instead for 
Did you mean: 

Problem when removing last element

Former Member
0 Kudos

Hi experts,

I have a problem when removing last element of LinksNode.

My context looks like this:

LinksNode

---nameAttribute

---LimitNode(singletone=false)

-


nameAttribute

When i remove last element i get ContextException.

What can be wrong ?

Slavik.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

HI Slavik,

Try setting the cardinality of the Linksnode as 0..n.

Former Member
0 Kudos

Hi Sathish,

The coordinality of both LinksNode and LinitNode is 0..n.

I simply do not understand why it removes all the elements without any problem, but throws the exception if i want to remove the last remained element.

Only when LinksNode.size() == 1 i get the exception.When i tried to debug the code i see that it successfully removes the last LinksNode element , but fails to remove it's LimitNode.

Slavik.

Former Member
0 Kudos

Please post your code.

Armin

Former Member
0 Kudos

Hi Armin,

On the nearest sunday when i am at work i will post my code.

Thank you all for the quick replies.

Regards,

Slavik.

0 Kudos

Hi,

This is my code that removes the link:

public void onActionRemoveLink(com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent )

{

//@@begin onActionRemoveLink(ServerEvent)

ILinksNode linksNode = wdContext.nodeLinks();

if (linksNode.size() > 0)

{

int linkIndex = linksNode.getLeadSelection();

ILinksElement linksElement = (ILinksElement)linksNode.getLinksElementAt(linkIndex);

linksNode.removeElement(linksElement);

}

//@@end

}

Former Member
0 Kudos

But this code does not delete the last element but the lead selected one and this fails if the lead selection is -1.

Try this:


ILinksNode node = wdContext.nodeLinks();
int n = node.size();

/* To delete last element: */
if ( n > 0 )
{
  ILinksNodeElement last = node.getLinksNodeElement(n - 1);
  node.removeElement(last);
}

/* To delete lead selected element */
if ( node.getLeadSelection() != IWDNode.NO_SELECTION )
{
  ILinksNodeElement selected = node.currentLinksNodeElement();
  node.removeElement(selected);
}

Armin

0 Kudos

Hi Armin,

In my code i try to delete the lead selected one. I have the problem only when there is only one element in the LinksNode.

Your code and my code both fails when i tried to delete the last element of the node when node's size is 1.

This is the exception message:

com.sap.tc.webdynpro.progmodel.context.ContextException: Node(ContentGroupsAndUserGroupsView.Links): no child node 'Limit' at index -1

In the debugger i saw that it not fails while removing the Links element but when tries to remove Links element Limit node which has singleton=false.

I want to mention that the above view gets all it's context data from the components controller by mapping.

I personally think that it is WD bug.

Regards,

Slavik.

Former Member
0 Kudos

Open an OSS message (BC-WD-JAV-RUN).

Armin

Former Member
0 Kudos

Hi,

I tried your scenario as follows

I Created a value node "Sample" with cardinality 0..n;selection 0..1

Then created a value node "SubSample" under node "Sample" with cardinality 0..n;seelction 0..1;singleton=false.

Then in wdDoInit of the view controller

IPrivateSampleView.ISampleElement ele = wdContext.nodeSample().createSampleElement();

ele.setSampleValue("Ram");

wdContext.nodeSample().addElement(ele);

wdComponentAPI.getMessageManager().reportSuccess("Size after creation "+wdContext.nodeSubSample().size());

IPrivateSampleView.ISubSampleElement Subele =wdContext.nodeSubSample().createSubSampleElement();

Subele.setSubSampleValue("Ram1");

wdContext.nodeSubSample().addElement(Subele);

Created a button in the view and in the action of the button

public void onActionButton(com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent )

{

//@@begin onActionButton(ServerEvent)

if(wdContext.nodeSample().size()>0)

{

wdComponentAPI.getMessageManager().reportSuccess("Size before removing "+wdContext.nodeSample().size());

IPrivateSampleView.ISampleElement ele = wdContext.nodeSample().getSampleElementAt(wdContext.nodeSample().getLeadSelection());

wdContext.nodeSample().removeElement(ele);

wdComponentAPI.getMessageManager().reportSuccess("Size after removing "+wdContext.nodeSample().size());

}

Ouput in the view after action

Size before removing 1

Size after removing 0

It is working fine.

0 Kudos

Hi Shriram,

I will check it.

Regards,

Slavik.

0 Kudos

Hi Armin and Shriram,

I have found the problem, just tell me if it is a bug or not.

If you bind inner singleton = false node ( Limit) to RadioButtonGroupByIndex, as i did, you will get the exception.

Can i bind some node to RadioButtonGroupByIndex when i want to remove all node's elements ?

The same problem occurs when using RadioButtonGroupByKey, RadioButton and even CheckBoxGroup.

Regards,

Slavik.

Former Member
0 Kudos

OSS message (BC-WD-JAV-RUN) is opened.

Slavik.

Answers (1)

Answers (1)

Former Member
0 Kudos

Do you want to remove only the last element? Like this:


ILinksNode node = wdContext.nodeLinksNode();
int lastIndex = node.size() - 1;
if (lastIndex >= 0)
{
  node.removeElement(node.getLinksNodeElementAt(lastIndex));
}

Armin

Former Member
0 Kudos

Hi Armin,

In my application i can remove any element of the LinksNode. But the problem is that when i have only one element in the node i get the exception. The exception tells that i can not remove LimitNode element with index -1.

Regards,

Slavik.

Former Member
0 Kudos

Please post your code.

Armin