cancel
Showing results for 
Search instead for 
Did you mean: 

How to access a dynamic created attribute in a context node?

Former Member
0 Kudos

<i>Hello,</i>

<i>who could help? I can't set a value for a dynamically created attribute which is bind to a table.</i>

<i>My context of the view looks as follow (is defined in NetWeaver):</i>

- Context

- Availability (Node)

- vctxService (Attribute)

- vctxServiceDesc (Attribute)

- ... (further predefined attributes)

- ... (some have to be set dynamically as follows)

<i>Then I have added attributes dynamically in the wdDoModifyView(...) - method, as follows:</i>

...

for (int i = 0; i < max; i++) {

// some code to dynamically create table columns

...

// adding attributes dynamically

IWDAttributeInfo attrInfo = wdContext.nodeAvailability().getNodeInfo(). addAttribute("vctxAvailability_" + i, "ddic:com.sap.dictionary.string");

tv.bindText(attrInfo); // bind to TextView in table

...

}

<i>In the method onPlugFrom... I tried to set the values for the attributes "vctxAvailability_ + i" as follows:</i>

for (int i = 0; i < max; i++) {

IAvailabilityElement newAvailNodeElement = wdContext.createAvailabilityElement();

// some values will be set for the

// predefined attributes of AvailabilityNode

// newAvailNodeElement.set...( value );

// newAvailNodeElement.setVctxService( xy.getServ() );

...

// now the values of dynamically created and added

// attributes in AvailabilityNode will be added

// THIS DOESN'T WORK

newAvailNodeElement.setAttributeValue ("vctxAvailability_" + i, "value" + i);

...

}

<i>It would be great if someone could help me.

Thanks in advance.

Kind regards,

Carsten</i>

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi,

Very much thanks for the help.

One point is unclear for me. If I create dynamically a table in wdDoModifyView(...). Then create the dynamic attributes in onPlugFrom...(...). Where should I do then the binding from the attributes to the table - and how will it work if onPlugFrom...(...) will be called before wdDoModifyView(...). The table doesn't exist if onPlugFrom...(...) is called before wdDoModifyView(...).

Is it a way to put all created nodes with the new attributes in a Vector and iterate them in wdDoModifyView(...) to bind them to the table?

Thanks in advance,

Carsten

Former Member
0 Kudos

Hi Carsten,

you're confused, aren't you ;-)? I'll try to clarify it once again:

1. You can add attributes/nodes to the context of a view controller everywhere, <b>not</b> only in wdDoModifyView(). If you use the wdDoInit() method for adding, this should be successful in any case (e.g. the attributes will be there, when they are needed), since it's the first method called during a controller lifecycle.

2. You should create/add UI elements or modify UI element properties in wdDoModifyView(). This includes the binding of the dynamically created context nodes/attributes to UI elements, which has been created dynamically or at design time.

3. The context doesn't "loose" the attributes/nodes you add dynamically, if the method where there were created is left. It will keep it as long as the controller "lives" or until you reset the context (nodes).

4. So, the simple conclusion is: Add the nodes/attributes in wdDoInit() or in the onPlugFrom() method and bind them to the dynamically created UI elements in wdDoModifyView().

Hope that helps.

Regards

Stefan

Former Member
0 Kudos

Hi Stefan,

Thanks a lot for your help. Yes in this case I were a little bit confused But now I have done it as you described and it works fine !

Thanks and kind regards,

Carsten

Former Member
0 Kudos

Hi Carsten,

i'm not quite sure about the sequence the methods are invoked in your scenario. Maybe the onPlugFrom..() method is called before wdDoModifyView() and so you access the dynamic attributes before they are actually created.

By the way, there's no need to add the attributes in wdDoModifyView() (binding the UI elements is something different), doing this in wdDoInit() would be much more safer in this case, since wdDoInit() is always the first method invoked when a controller is accessed for the first time.

Hope that helps.

Regards

Stefan

Former Member
0 Kudos

Carsten,

Here is a sample code that creates context attributes dynamically and also sets values:

//Creates a node

IWDNodeInfo nodeInfo = wdContext.wdGetAPI().getRootNodeInfo().addChild("TestNode", null, true, true, false, true, false, true, null, null, null);

//If you want to bind the node to a model node then the

//second argument to the above method should be the

//model class.

//Creates an attribute under the node just created.

IWDAttributeInfo testAttrib = wdContext.wdGetAPI().getRootNodeInfo().getChild("TestNode").addAttribute("testAttrib", "ddic:com.sap.dictionary.string");

IWDNodeElement testNode = wdContext.getChildNode("TestNode", IWDNode.LEAD_SELECTION).getCurrentElement();

IWDNode testNode2 = wdContext.getChildNode("TestNode", IWDNode.LEAD_SELECTION);

//Now you can bind testNode with the Model Node

//You can also set a value to the newly created attribute

testNode.setAttributeValue("testAttrib", new String("Value"));

Hope this helps.

Shakeel