| Home • Tips • Tutorials • Sample Specs • Certification Q's • Interview Q's • Jobs • Testimonials • Contact Us | ||
Document Categories:
Email a FriendWhat's New?
Contribute?What's Hot? |
Dynamic Runtime Manipulation-Context & View layout using Web Dynpro for JavaBy 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 :
Part 1: Creating View Context
Dynamically 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 } Click here to continue... |
|
|
Please send us your feedback/suggestions at webmaster@SAPTechnical.COM Home • Contribute • About Us • Privacy • Terms Of Use • Disclaimer • Safe • Companies: Advertise on SAPTechnical.COM | Post Job • Contact Us ©2006-2007 SAPTechnical.COM. All rights reserved. All
product names are trademarks of their respective companies. SAPTechnical.COM,
Inc. is in no way affiliated with SAP AG. Graphic Design by Round the Bend Wizards |
||