cancel
Showing results for 
Search instead for 
Did you mean: 

How to clear a Node from the Context ?

Former Member
0 Kudos

Hello,

Let's say my contects contains a node called unit which contains one attribute called unitName. If I want to remove from Context all the previously elements from this node before I add new element how do I do that?

Accepted Solutions (1)

Accepted Solutions (1)

0 Kudos

well it is simple procedure normally it should work ok

may be try wdcontext.curentnodename.setattribute("");

try to set the attribute which is bind with that combo.

I do not know ur node structure, the node which u invalidate is the same node which contains attribute which is bind with first combo?

yasir

Former Member
0 Kudos

My node structure is like this:

Node: location, attribute: locationName

Node: unit, attribute: unitName

The unit shouls change according to the location the user selects

Noufal: the current node doesn't contain a method called getItem(). are you sure your syntax is correct?

Former Member
0 Kudos

Hi,

I tried out your scenario. I'll brief what I have done.

I created two dropdown boxes.. Mapped it to two context attrbutes not context nodes.These attributes have been bound to two simple types.

The attributes are dept and size.

when I select shirt as the dept,I get 32 as size.

when i select T-shirt as dept, I get XXL as size.

The code is as follows

public void onActionSelect( wdEvent )

{

if(wdContext.currentContextElement().getDept().equals("Shirt")){

IWDAttributeInfo info=wdContext.getNodeInfo().getAttribute("size");

ISimpleTypeModifiable simpletype=info.getModifiableSimpleType();

IModifiableSimpleValueSet value=simpletype.getSVServices().getModifiableSimpleValueSet();

value.clear();

value.put("32","32");

}else{

IWDAttributeInfo info=wdContext.getNodeInfo().getAttribute("size");

ISimpleTypeModifiable simpletype=info.getModifiableSimpleType();

IModifiableSimpleValueSet value=simpletype.getSVServices().getModifiableSimpleValueSet();

value.clear();

value.put("XXL","XXL");

}

}

Please check the same and do revert for any clarifications.

Do send in your feedbacks

Regards

Noufal

Former Member
0 Kudos

10X Noufal, I simply forgot to put value.clear() and now that I see your code I see it. Thanx a lot for you kind tolerant help!

Answers (3)

Answers (3)

Former Member
0 Kudos

Hi,

Just as Noufal has said you should clear the value set .You can also check whether the value set contains any elements using isEmpty().You are invalidating the node and entering new values based on the selection in the first combo.then you are actually appending to the valueset.

Regards

Rohit.R.Krishnan

Former Member
0 Kudos

Hi,

If you want to manually delete the attributes right click on contect node and delete the attributes you are intended to delete and add fresh attributes..

(hope this what you are looking for)

Regards,

RK

Former Member
0 Kudos

Hi,

Let the scenario be as follows.

shirt->39,40,42

T-shirt-M,L,XL

Let the first node be itemnode->attribute item

Let the second node be categorynode- attribute size

if(wdcontext.currentatemnode.getitem.equals("T-shirt")){

wdcontext.nodecategorynode().invalidate();

//now set the values for the category node

}

This is just a brief example hope would help.

Regards

Noufal

0 Kudos

hi,

you can do wdcontext.nodename.invalidate();

i hope this is waht u are looking for....

Regards

Yasir Noman

Former Member
0 Kudos

Hello Yasir,

I'm not sure, let me describe you my problem:

I have a combo box which contains departments list and another combo which contains it's related departments.

Whenever the user changes the department at the first combo an event raises which should get the related departments and put them at the second combo.

The code for the event looks like this:


public void onActionchangeUnitByLocation(com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent )
  {
    //@@begin onActionchangeUnitByLocation(ServerEvent)
    
	String selectedLocation = wdContext.currentLocationElement().getLocationName();
	String filter = new String("(& (sAMAccountName=*) (mojHebFirstName=*) (physicalDeliveryOfficeName=" + selectedLocation + ") (department=*))");
	NamingEnumeration results = getLdapResults(filter);
	
	// Clear Previous Unit Elements in case there are any
	wdContext.nodeUnit().invalidate();
	 
	// Create New Unit Element
	IPrivateParametersView.IUnitElement newUnitElement = wdContext.createUnitElement();
	ISimpleTypeModifiable unitType = wdThis.wdGetAPI().getContext().getModifiableTypeOf("unit.unitName");
	IModifiableSimpleValueSet unitValues = unitType.getSVServices().getModifiableSimpleValueSet();
	
	int i = 0;
	while(results.hasMoreElements())
	{
		try 
		{
			SearchResult result = (SearchResult)results.nextElement();
			Attributes attributes = result.getAttributes();
			String department = attributes.get("department").get(0).toString();
			unitValues.put(department,department);
			i++;
		} 
		catch (NamingException e) 
		{
			e.printStackTrace();
		}
	}

	// Add elements to the Context
	wdContext.nodeUnit().addElement(newUnitElement);
	wdContext.currentContextElement().setLastName("I is: " + i);
	
    //@@end
  }

The problem is that the combo box still contains previous results and doesn't "clean". The i integer is for debugging purpose. What could be the problem here?