cancel
Showing results for 
Search instead for 
Did you mean: 

dynamiclly generated dropdownbyindex

0 Kudos

hi everyone,

i need to create a dropdownbyindex-element dynamiclly in the code, with values from an dynamiclly generated arraylist. but i can only bind a value-node to the ddbi-element.

so. how can i create a value-node with one value-attribute dynamiclly and set the value according to the arraylist?

thanks and best regards,

constantin

Accepted Solutions (1)

Accepted Solutions (1)

0 Kudos

it doesnt work for me...

heres my code (6.40)

IWDDropDownByIndex ddbi = (IWDDropDownByIndex) view.createElement(IWDDropDownByIndex.class, "table_selection_ddbi");
IWDNodeInfo nodeInfo = wdContext.getNodeInfo().addChild("table_selection_node", null, true, true, true, false, false, true, null, null, null);
nodeInfo.addAttribute("value", "ddic:com.sap.dictionary.string");			
wdContext.getChildNode("table_selection_node", 0).bind((List) list);
ddbi.bindTexts("table_selection_node");

please help

regards,

constantin

Former Member
0 Kudos

Do you really need to create the UI element and the context node programmatically? What is the use-case?

Why not just create the DropDownByIndex UI element and the context node, say "Items" at design-time and provide a supply-function "supplyItems()" for the context node that uses your list as input. Whenever the list changes, just call wdContext.nodeItems().invalidate() which triggers a call of the supply function.

Armin

0 Kudos

hi armin,

because i need to create an application, which is totally database-controlled. thats why every view needs to be view/ui-element needs to be created dynamiclly...

Former Member
0 Kudos

Hi,

To resolve your error,

Your array list need to be slightly changed as follows



IWDNodeInfo nodeInfo = wdContext.getNodeInfo().addChild("Node", null, true, CMICardinality.ONE,
			  					CMICardinality.ONE, true, null);
	  nodeInfo.addAttribute("Test", "ddic:com.sap.dictionary.string");
	  
	  ArrayList<IWDNodeElement> arr = new ArrayList<IWDNodeElement>();
	  
	  for(int x=0; x<5;x++)
	  {
		  IWDNodeElement element = wdContext.getChildNode("Node", 1).createAndAddElement();
		  element.setAttributeValue("Test", "a");
		  arr.add(element);
	  }

	  wdContext.getChildNode("Node", 0).bind(arr);

Regards

Ayyapparaj

0 Kudos

hi Ayyapparaj KV,

first of all.. thanks for your help.. but im using 6.40 and not the 7.00

still no solution in sight...

Former Member
0 Kudos

Example: Create a context node "Items" with a string attribute "text", create a DropDownByIndex "ItemSelector", bind it to the node. Fill the node from some array of strings.


void wdDoInit()
{
  /* Create the meta-data */
  IWDNodeInfo itemsNodeInfo = wdContext.getNodeInfo().addChild
  (
    "Items", 
    null, /* value node */ 
    true, /* singleton */ 
    false, true, /* cardinality = 0:n */
    false, false, /* selection = 0:1 */
    true, /* initialize lead-selection */
    null, /* data type */
    null, null /* no supplier and disposer */
  );
  itemsNodeInfo.addAttribute("text", "ddic:com.sap.dictionary.string");

  /* Fill the node from sample data */
  String[] values = { "First", "Second", "Third" };
  IWDNode itemsNode = wdContext.getChildNode("Items", 0);
  for (int i = 0; i < values.length; ++i)
  {
    IWDNodeElement e = itemsNode.createElement();
    e.setAttributeValue("text", values<i>);
    itemsNode.addElement(e);
  }
}

wdDoModifyView(...)
{
  if (firstTime)
  {
    IWDUIElementContainer top = (IWDUIElementContainer) view.getRootElement();
    IWDDropDownByIndex itemSelector = (IWDDropDownByIndex) view.createElement(IWDDropDownByIndex.class, "ItemSelector");
    itemSelector.bindTexts("Items.text");
    top.addChild(itemSelector);
  }
}

Übungsaufgabe: Create an action and assign it to the "onSelect" event of the drop-down list. (Hint: You have to use a predefined event handler method.)

Armin

0 Kudos

thank you armin!!!!

thats exactly what i needed!

Former Member
0 Kudos

Fine. I recommend Chris Whealy's book "Inside Web Dynpro for Java" which has examples like this.

Armin

Answers (4)

Answers (4)

amolgupta
Active Contributor
0 Kudos

try...

wdContext.node<nodename>().bind((List)<arrayListObject>);

i.e. typecast your ArrayList object to a List object.

i used it and it worked fine.

regards,

-Amol Gupta

Former Member
0 Kudos

Hi,

how can i create a value-node with one value-attribute dynamiclly and set the value according to the arraylist?

Following is the code to create a value node and attribute


IWDNodeInfo nodeInfo = wdContext.getNodeInfo().addChild("Node", null, true, CMICardinality.ONE,
			  					CMICardinality.ONE, true, null);
	  nodeInfo.addAttribute("Test", "ddic:com.sap.dictionary.string");

ArrayList arr = new ArrayList();
	  arr.add("a");
	  arr.add("b");
	  arr.add("c");
	  wdContext.getChildNode("Node", 0).bind(arr);

Regards

Ayyapparaj

0 Kudos

hi Ayyapparaj KV,

thats how i assumed it and tried your example but i cant bind an arraylist to the node. i get the following error which is self-explaining... i need to transform the arraylist to a node element.. but how?

com.sap.tc.webdynpro.progmodel.context.ContextException: DataNodeInfo(WDGeoView.table_selection_ddbi_node): you must bind NodeElements to a value node

remember.. i cant set the node and the attributes in the context by hand.. they need to be set by runtime

regards,

constantin

Former Member
0 Kudos
amolgupta
Active Contributor
0 Kudos

hi,

add a drop down by index UI element to the view.

make a node in the context with 0-n cardinality.

i.e. the node can hold 0 to n elements in it.

make the attributes in the node.

make instances of the node as follows.

read your vector object in a loop...

and add elements for each element in the drop down.

For(initialisation; //readVectorOneByOne() ; increment)

{

IPublic<viewname>.I<NodeName>Element objEle = wdContext.node<NodeName>().create<NodeName>Element();

objEle.set<ContextElement>();

objEle.set.....();

wdContext.node<NodeName>().addElement(objEle);

}

regards,

-Amol Gupta