10

Click here to load reader

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

Embed Size (px)

Citation preview

Page 1: Dynamic Runtime Manipulation-Context & View Layout Using Web Dynpro for Java

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  

Page 2: Dynamic Runtime Manipulation-Context & View Layout Using Web Dynpro for Java

 

Page 3: Dynamic Runtime Manipulation-Context & View Layout Using Web Dynpro for Java

 

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

Page 4: Dynamic Runtime Manipulation-Context & View Layout Using Web Dynpro for Java

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");

Page 5: Dynamic Runtime Manipulation-Context & View Layout Using Web Dynpro for Java

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.stringPart 2: Creating View Layout DynamicallyFor the above Created Dynamic Context we ar going to create View layout.Locate The method WDDOModfify viewpublic 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();) {

Page 6: Dynamic Runtime Manipulation-Context & View Layout Using Web Dynpro for Java

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 

 

Page 7: Dynamic Runtime Manipulation-Context & View Layout Using Web Dynpro for Java

Enter The name Of Application 

 

Click on “Next” 

Click on “Next” 

Page 8: Dynamic Runtime Manipulation-Context & View Layout Using Web Dynpro for Java

Click on Finish 

       Build The Project 

 

       Create Archive 

Page 9: Dynamic Runtime Manipulation-Context & View Layout Using Web Dynpro for Java

 

       Deploy New Archive And Run 

Output :