cancel
Showing results for 
Search instead for 
Did you mean: 

how to create UI Component in runtime in WebDynpro

Former Member
0 Kudos

hi friends,

I need some sample code and procedure to create UI elements in runtime

help me...

waiting for reply....

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi,

Check the following link for creating dynamic UI elements with code,

http://help.sap.com/saphelp_nw70/helpdata/en/89/73a840bd6d3c13e10000000a155106/frameset.htm

<a href="http://help.sap.com/saphelp_nw70/helpdata/en/89/73a840bd6d3c13e10000000a155106/frameset.htm">Dynamically Creating the Form</a>

<a href="https://www.sdn.sap.comhttp://www.sdn.sap.comhttp://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/74cda090-0201-0010-6b91-f85b2489f765">Sample Apllications</a>

Answers (5)

Answers (5)

former_member187990
Participant
0 Kudos
Former Member
0 Kudos

Hi,

Some general info about dynamic UI generation

1.UI generation during runtime is done only in wdDoModifyView method of your view controller.

2. Always use if(firsttime){code for UI generation}.This will create the UI only once.

Else for every change/acton in the view wdDoModifyView will be called and it will try to create a duplicate UI element which will lead to errors.

3. For dynamic UI generation you have to first create the element

IWD<UI element> <some name> = IWD(UI element)view.createElement(IWD<UI Element>.class,"<ID of the UI element>");

for Inputfield

IWDInputField input = (IWDInputField)view.createElement(IWDInputField.class,"inputName");

4. Now on the instance i.e <some name> you can set the propertiese of the UI element as <some name>.set<UI element property>

5. Once you create ans set the required property for the UI element, you have to add that UI element to the Container.

If you have only one container then

IWDTransparentContainer container = (IWDTransparentContainer)view.getRootElement();

6. Add the dynamically created UI element to the container

container.addChild(<some name>);

Former Member
0 Kudos

Hi Balaji,

Check the following links,they will surely help u ,

the following link tells u all abt dynamic creation of UI elements

https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/58a7e390-0201-0010-abb1-8eec7eb7...

following is one exercise,

https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/74cda090-0201-0010-6b91-f85b2489...

https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/6fdae690-0201-0010-a580-d104b459...

Dont forget to Reward me with points if the answer is helpful to you.

Former Member
0 Kudos

Hi Balaji,

Here i give some example code of creating an UI Component in runtime in WebDynpro,

first u create a view,

and u enter this code for wdDoInit( )

//get reference to a meta data for context root node

IWDNodeInfo rootnodeInfo=wdContext.getNodeInfo();

//create a new meta data object for a node sales ordes

IWDNodeInfo soNodeInfo =rootNodeInfo.addChild("SalesOrders",

null,

true,

false, true,

false, false,

true,

null,

null,

null);

//create a four attripute in new salesorder

soNodeInfo.addAttribute("OrderNo",

"ddic:com.sap.dictionary.integer");

soNodeInfo.addAttribute("SalesDate",

"ddic:com.sap.dictionary.date");

soNodeInfo.addAttribute("SalesRep",

"ddic:com.sap.dictionary.string");

soNodeInfo.addAttribute("LongText",

"ddic:com.sap.dictionary.string");

//get ref to instence the sales order

IWDNode soNode = wdContext.getChildNode("SalesOrders", 0);

//create a new selection

IWDNodeElement soElement = soNode.createElement();

soElement.setAttributeValue("OrderNo", QHZ Integer(100));

soElement.setAttributeValue("SalesDate",

new Date(System.currentTimeMillis()));

soElement.setAttributeValue("SalesRep", "Homer Simpson");

soElement.setAttributeValue("LongText", "Printer Supplies");

soNode.addElement(soElement);

}

and write the code for wdModifyView()

if(firstTime)

{

IWDTransparentContainer rootElement=(IWDTransparentContainer)view.getRootElement();

rootElement.createLayout(IWDMatrixLayout.class);

IWDNodeInfo NnodeInfo=wdContext.getChildNode("SalesOrders",0).getNodeInfo();

for(Iterator iter=NnodeInfo.iterateAttributes();iter.hasNext();)

{

IWDAttributeInfo NAttrinfo=(IWDAttributeInfo)iter.next();

IWDLabel label=(IWDLabel)view.createElement(IWDLabel.class,NAttrinfo.getName()+"Label");

label.setText(NAttrinfo.getName());

label.createLayoutData(IWDMatrixHeadData.class);

label.setDesign(WDLabelDesign.LIGHT);

label.setLabelFor(NAttrinfo.getName()+"Input");

rootElement.addChild(label);

IWDInputField iofield=(IWDInputField)view.createElement(IWDInputField.class,NAttrinfo.getName()+"Input");

iofield.createLayoutData(IWDMatrixData.class);

iofield.bindValue(NAttrinfo);

rootElement.addChild(iofield);

}

}

Message was edited by:

Vinoth Raja.V

former_member187990
Participant
0 Kudos

Hi Balaji,

Here is the Code for Creating Label UI Element Dynamically.

if(firstTime)

{

IWDTransparentContainer rootElement =(IWDTransparentContainer) view.getRootElement();

IWDLabel label =(IWDLabel) view.createElement(

IWDLabel.class,

"LabelName" + "Label");

label.setText(“SampleText”);

label.createLayoutData(IWDMatrixHeadData.class);

label.setDesign(WDLabelDesign.LIGHT);

label.setLabelFor(soAttrInfo.getName() + "Input");

rootElement.addChild(label);

}

Place this code in WDDoModifyView() so that it will be added only once to the screen because of FirstTime variable.