on 07-12-2007 11:17 PM
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.
HI Slavik,
Try setting the cardinality of the Linksnode as 0..n.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
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
}
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
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.
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.
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.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
80 | |
9 | |
9 | |
7 | |
7 | |
7 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.