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

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

|Views: 425|Likes:
Published by Werathep Chaladee

More info:

Published by: Werathep Chaladee on Aug 16, 2010
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as DOC, PDF, TXT or read online from Scribd
See more
See less

10/25/2012

pdf

text

original

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're Reading a Free Preview

Download
scribd
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->