0% found this document useful (0 votes)
532 views

Dynamic Runtime Manipulation-Context &amp View Layout Using Web Dynpro For Java

This document discusses dynamically manipulating a web application's runtime context and view layout using Web Dynpro for Java. It provides a solution for dynamically adding nodes, attributes, and elements to the view controller context at runtime. It also describes how to dynamically create the view layout based on the dynamic context by adding labels and input fields for each attribute to a matrix layout. The code examples show how to implement this by adding nodes, attributes, and elements to the context and view programmatically in the view controller and view modification methods.

Uploaded by

Toey Chaladee
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
532 views

Dynamic Runtime Manipulation-Context &amp View Layout Using Web Dynpro For Java

This document discusses dynamically manipulating a web application's runtime context and view layout using Web Dynpro for Java. It provides a solution for dynamically adding nodes, attributes, and elements to the view controller context at runtime. It also describes how to dynamically create the view layout based on the dynamic context by adding labels and input fields for each attribute to a matrix layout. The code examples show how to implement this by adding nodes, attributes, and elements to the context and view programmatically in the view controller and view modification methods.

Uploaded by

Toey Chaladee
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 9

Dynamic Runtime Manipulation-Context & View layout using Web Dynpro for Java

By Chandra Dasari, YASH Technologies 

Customer-Business Case 

There might be some scenarios where in we need to dynamically add nodes, their attributes to the view controller context. In this case the View Layout needs
to be defined dynamically using the above context nodes and the attributes. 

Following is the solution for the same: 

Project name: DynamicUIManip

Package com.sap.training

Window name: MainWindow

View Name: Dynamic View 

Click on “Finish”: 

Path-> NWDS->File->New-> WebDynPro Project  


 
 

Since everything in this component will be created dynamically at runtime, both the view context and the view layout will remain empty. 
View Context :

We can find here the context is empty. The context will be creating dynamically at runtime.

Part 1: Creating View Context Dynamically 

Implementation In View Controller


public void wdDoInit()
{
//@@begin wdDoInit()
IWDNodeInfo rootNodeInfo = wdContext.getNodeInfo();
IWDNodeInfo soNodeInfo = rootNodeInfo.addChild(
"SalesOrders",null,true,false,true,false,true,true,null,null,null);
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");

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


IWDNodeElement soElement = soNode.createElement();
soElement.setAttributeValue("OrderNo",new Integer(10));
soElement.setAttributeValue("SalesDate",new Date(System.currentTimeMillis()));
soElement.setAttributeValue("SalesRep","Simpson");
soElement.setAttributeValue("LongText","Printer Supplies");

soNode.addElement(soElement);

//@@end
}
Now the Node SalesOrder IS created with the following Attributes:
SalesOrder (node)
OrderNo :ddic:com.sap.dictionary.integer
SalesDate: ddic:com.sap.dictionary.date
SalesRep: ddic:com.sap.dictionary.string
LongText: ddic:com.sap.dictionary.string
Part 2: Creating View Layout Dynamically
For the above Created Dynamic Context we ar going to create View layout.
Locate The method WDDOModfify view
public static void wdDoModifyView(IPrivateMainView wdThis, IPrivateMainView.IContextNode
wdContext,com.sap.tc.webdynpro.progmodel.api.IWDView view, boolean firstTime)
{
//@@begin wdDoModifyView

if (firstTime) {
IWDTransparentContainer rootElement =
(IWDTransparentContainer) view.getRootElement();

rootElement.createLayout(IWDMatrixLayout.class);
IWDNodeInfo soNodeInfo =
wdContext.getChildNode("SalesOrders", 0).getNodeInfo();

for (Iterator iter = soNodeInfo.iterateAttributes();


iter.hasNext();) {
IWDAttributeInfo soAttrInfo =
(IWDAttributeInfo) iter.next();
IWDLabel label =(IWDLabel) view.createElement(
IWDLabel.class,
soAttrInfo.getName() + "Label");

label.setText(soAttrInfo.getName());
label.createLayoutData(IWDMatrixHeadData.class);
label.setDesign(WDLabelDesign.LIGHT);
label.setLabelFor(soAttrInfo.getName() + "Input");

rootElement.addChild(label);

IWDInputField ioField =
(IWDInputField) view.createElement(
IWDInputField.class,
soAttrInfo.getName() + "Input");

ioField.createLayoutData(IWDMatrixData.class);
ioField.bindValue(soAttrInfo);
rootElement.addChild(ioField);
}
// @@end
}

Part3- Creating Application and Testing

       Create web Dynpro Application: DynamicManipAppl 

 
Enter The name Of Application 

Click on “Next” 

Click on “Next” 
Click on Finish 

       Build The Project 

       Create Archive 


 

       Deploy New Archive And Run 

Output :

You might also like