cancel
Showing results for 
Search instead for 
Did you mean: 

Dynamic Creation of UI Elements

Former Member
0 Kudos

Hi,

Can anyone help me to create a DropDownByIndex and CheckBox dynamically in the Implementation tab of a View. Also I am not able to insert values into the dropdown.

If someone send the code it would be very helpful

Thanks

Kalyan

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

First, you don't need to create the context structure programmatically like the other post suggests. This is only confusing.

Say, you have created a node "Items" (cardinality 0:N, selection 0:1) with an attribute "Text" in NWDS.

To create a DropDownByIndex that displays the elements of node "Items" as its items, you write the following code in method wdDoModifyView():


IWDDropDownByIndex dd = (IWDDropDownByIndex) view.createElement(IWDDropDownByIndex.class, null);
dd.bindTexts("Items.Text");

IWDUIElementContainer parent = (IWDUIElementContainer) view.getElement("ID-of-parent");
parent.addChild(dd);

For a CheckBox, you need a boolean attribute for storing the "checked" state. Works the same way.

To avoid creation of the element on every call of wdDoModifyView(), you should place this code inside an if-statement that guards when to create the element, e.g. if (firstTime).

Armin

Answers (3)

Answers (3)

Former Member
0 Kudos

Hai Kalyan,

write the code below in wdDoModify()

if(firstTime){
    	IWDCheckBox icb=(IWDCheckBox)view.createElement(IWDCheckBox.class,null);
    	IWDDropDownByIndex idbi=(IWDDropDownByIndex)view.createElement(IWDDropDownByIndex.class,null);
    }

regards,

naga raju

suresh_krishnamoorthy
Active Contributor
0 Kudos
Former Member
0 Kudos

Hi,

Create one static node name like 'NodeA'

Create one Node(MultiNode) with one attribute(roles) using the following code. Inside the DoInit() method

Step 1:

IPrivate<ViewName>.INodeAElement ele = wdContext.createNodeAElement();

wdContext.nodeNodeA().addElement(ele);

IWDNodeInfo multipleinfo = wdContext.nodeNodeA().getNodeInfo();

IWDNodeInfo multiplenode = multipleinfo.addChild("MultiNode" , null, true, false, true, true, false, true, null, null, null);

multiplenode.addAttribute("roles", "ddic:com.sap.dictionary.string");

Step 2:

Assign values for Dropdown. Here i assigned 5 values.if you want assign values from database/BAPI also.

IWDNode node1 = wdContext.nodeNodeA().getChildNode("MultiNode", IWDNode.NO_SELECTION);

IWDNodeElement elem1;

for(int s=0;s<5;s++){

elem1 = node1.createElement();

elem1.setAttributeValue("roles","Value"+s);

node1.addElement(elem1);

}

Step 3:

Inside Domodifyview create IWDDropDownByIndex UI Element and Bind it.

IWDDropDownByIndex dropDownList = (IWDDropDownByIndex)view.createElement(IWDDropDownByIndex.class, "drop");

IWDAttributeInfo info = wdContext.getNodeInfo().getChild("NodeA").getChild("MultiNode").getAttribute("roles");

dropDownList.bindTexts(info);

Finally add this Dropdown into container. Like this you can create more Dropdown and add action to the dropdown as dynamically.

<b>Valuable answer=points</b>

Kind Regards,

S.Saravanan.

Former Member
0 Kudos

Hi Sarvanan,

Your code has helped me out to get the required output.

Thanks

Kalyan