Professional Documents
Culture Documents
Contributing Speakers
Marco Ertel
NW PM Operations AP, Web Dynpro PM, SAP AG
Bertram Ganz
NWF Application UI, Web Dynpro Java Runtime, SAP AG
Gaby Wenneker
NW DT Development Framework, SAP AG
Michael Wenz
NW DT Development Framework, SAP AG
Dynamic UI Generation Debugging of Web Dynpro Applications Web Dynpro Internationalization Object Value Selector
Dynamic UI Generation Debugging of Web Dynpro Applications Web Dynpro Internationalization Object Value Selector
Dynamic UI Generation
Currently we support 4 flavors of dynamic generating UI: Dynamic UI Manipulation Dynamic Context Creation Dynamic Action Creation Dynamic Metadata
Dynamic UI Generation
Although we highly recommend the static Web Dynpro approach, there are situations when dynamic generation is required.
Web Dynpro itself needs dynamic generation for Highly configurable applications Some portal integration application Framework developers Customization and Personalization
The methodology of dynamic programming is integrated in a way, that it nicely cooperates with the static Web Dynpro approach. It is possible to mix static declarations with dynamic enhancements
Example import com.sap.tc.webdynpro.clientserver.uielib.standard.api.*; ... public static void wdDoModifyView ( IPrivateDynamicView wdThis, IPrivateDynamicView.IContextNode wdContext, Creates an Input Field IWDView view, boolean firstTime) { //@@begin wdDoModifyView if (firstTime) { IWDInputField input = (IWDInputField) view.getElement(someInput); input.setEnabled(false); } //@@end }
SAP AG 2004, SAP TechEd / PRTL351 / 8
public static void wdDoModifyView ( IPrivateDynamicView wdThis, IPrivateDynamicView.IContextNode wdContext, IWDView view, boolean firstTime) { //@@begin wdDoModifyView //@@end }
firstTime of the type boolean: This is true only if wdDoModifyView is called for the first time during the life cycle of the corresponding view. view: Reference to the layout controller of the view. wdThis: Reference to the IPrivate interface of the view controller . wdThis allows access to the controller context; it also allows triggering outbound plugs and events and access to action objects as well as controllers used. wdContext: Reference to the root context node of the view controller (for the current context).
IWDView Interface
Example
The view parameter of wdDoModifyView method allows you to access a views UI Elements. To get a reference to your views UI element you use the getElement(String id) method where the id is the name you gave the UI element. Once you have obtained a reference to a UI Element you can change its properties.
SAP AG 2004, SAP TechEd / PRTL351 / 11
Example
The view parameter of wdDoModifyView method allows you to create UI elements. Once you have created your UI element you can modify its default properties. Some UI elements must be bound to a context attribute (ie Input Fields)
SAP AG 2004, SAP TechEd / PRTL351 / 12
Example
IWDTransparentContainer container = (IWDTransparentContainer) view.getElement("RootUIElementContainer"); IWDInputField inputfield = (IWDInputField) view.createElement(IWDInputField.class, "InputField1"); inputfield.setVisible(WDVisibility.VISIBLE); container.addChild(inputfield);
To position a UI element in your view you must first get access to the UI Container you want to add it to (First line of code above). You can then call the container method addChild(IWDUIElement) or addChild(IWDUIElement, int index) to place the UI element in it.
SAP AG 2004, SAP TechEd / PRTL351 / 13
Dynamic UI Example
Example //@@begin wdDoModifyView if (wdContext.currentContextElement().getVisible()) { IWDLabel label2 = (IWDLabel)view.getElement("Label2"); label2.setEnabled(true); IWDLabel label3 = (IWDLabel)view.getElement("Label3"); label3.setVisible(WDVisibility.VISIBLE); IWDUIElementContainer container = label2.getContainer(); IWDLabel label4 = (IWDLabel)view.createElement(IWDLabel.class, "Label4"); label4.setText("Dynamically Created Label!"); container.addChild(label4, 2); } //@@end
SAP AG 2004, SAP TechEd / PRTL351 / 14
IWDInputField inputfield = (IWDInputField)view. createElement(IWDInputField.class, "InputField1"); IWDAttributeInfo test = wdContext.getNodeInfo(). addAttribute("AttributeA", "ddic:com.sap.dictionary.string"); wdContext.currentContextElement(). setAttributeValue("AttributeA", null); inputfield.bindValue("AttributeA");
SAP AG 2004, SAP TechEd / PRTL351 / 15
For each node that you create at design time, a method is generated on wdContext to access that nodes IWDNodeInfo interface. As shown here, we have two nodes, thus the following methods will exist on wdContext:
wdContext.nodeTestNode2().getNodeInfo() wdContext.nodeTestNode().getNodeInfo()
SAP AG 2004, SAP TechEd / PRTL351 / 16
IWDAttributeInfo test = Create an Attribute wdContext.getNodeInfo(). addAttribute("AttributeA", "ddic:com.sap.dictionary.string"); wdContext.currentContextElement(). setAttributeValue("AttributeA", null); inputfield.bindValue("AttributeA");
Bind the newly created attribute to the input field
SAP AG 2004, SAP TechEd / PRTL351 / 18
To access a dynamically created context element use the follow methods: Nodes:
wdContext.currentContextElement().node() .getChildNode(String, int).getCurrentElement();
Attributes:
wdContext.currentContextElement().getAttributeValue(String)
IWDNodeInfo node = wdContext.getNodeInfo(). addChild("DynamicNode", null, true, true, false, false, false, true, null, null, null); node.addAttribute("MyAttr", ddic:com.sap.dictionary.string");
Now we can bind a input fields value to this node binding context values to UI elements should occur in wdDoModifyView():
theInput.bindValue("DynamicNode." + fld.getName());
Once the binding has occurred we need to access the context variable to get the users input this is generally done in an action event handler: IWDNode node = wdContext.currentContextElement().node().getChildNode("DynamicNode", 0); IWDNodeElement nodeElement = node.getCurrentElement(); String myAttr = (String)nodeElement.getAttributeValue("MyAttr");
Dynamic Actions
Actions may be created dynamically, but the event handler must be already available! This means we can dynamically create actions, but we can not dynamically create code! Dynamically created actions can be bound to UI elements much the same way design time declared actions are bound to UI Elements. Dynamic created actions must reuse some static declared event handler and its signature! This is achieved by using wdThis.wdCreateAction(). ()
Example
1. Obtain the name of the parameter associated with the UI elements event (For example: IWDCheckBox has a parameter associated with event onToggle named checked). 2. Create an action in the view controller. 3. Define a parameter for the action of the same data type as the event parameter. 4. Associate the event parameter with the action parameter.
The diagram shown here visualizes the concept of parameter mapping. On the client side, when the checkbox is clicked the event onToggle is fired, which sends a request containing the parameter checked to the server. This onToggle event is assigned to the onActionToggle() event handler, and its parameter isChecked has been mapped to the checked parameter of onToggle()
onToggle(boolean checked)
Server
public class DynamicView { public void onActionToggle(boolean isChecked) { } }
Request
Network
Dynamic Actions Parameter Mapping Example: Step 2 Now you can access your checkbox in the wdDoModifyView() method to create the parameter mapping; the code for this is shown below
Example
if (firstTime) { // Get a reference to the checkbox UI element IWDCheckBox cb = (IWDCheckBox)view.getElement("myCheckBox"); // Link the client-side event parameter checked to // the server-side action parameter checkBoxState cb.mappingOfOnToggle().addSourceMapping("checked", "checkBoxState");
}
Summary
Dynamic UI Generation Debugging of Web Dynpro Applications Web Dynpro Internationalization Object Value Selector
Agenda
Demo
Demo
Reserve the process for your debugging session (more than one server node)
SAP AG 2004, SAP TechEd / PRTL351 / 32
Breakpoint options
Use the context menu on a breakpoint to set conditions and breakpoint properties
1. Start debugging
Debug view
Allows you to manage the debugging of a program in the IDE Displays the stack frame for the suspended threads you are debugging (thread = node in the tree).
Editor view
Displays program line the debugger is currently executing If the program execution leads to a different class, Eclipse will open up the corresponding editor automatically
Variables view
Shows information about variables that are currently in scope (currently-selected stack frame and callstack) Hierarchical display of variable structure Content of variables can be checked in separate content area (based on toString() method) Content of variables may be changed
Breakpoints view
Shows a list of the currently set breakpoints and their state Allows to
Add new exception breakpoints Delete existing breakpoints Change the properties of existing breakpoints
Expressions view
Used to evaluate results of expressions
Hierarchical display of structure Content area (based on toString() method) Inspect command Watch expressions
Display view
Used to evaluate results of expressions
String-only representation of result (based on toString() method) Display command
Display view: text based expression evaluation Editor view: currently executed code
Suspend
Will pause execution and allows to view state of variables
Resume [F8]
This command resumes a suspended thread
Terminate
Will terminate execution of the program
Enter airline ID
IDE
Start Web Dynpro application from Web Dynpro explorer or run configuration Server does not need to be in debug mode
Exercise
Dynamic UI Generation Web Dynpro Debugging Web Dynpro Internationalization Object Value Selector
over locale-dependant XLF-files (XML Localization Interchange File Format, designtime) into generated Java property-files (runtime). XLF-Files are only relevant for the translation process and can be edited at designtime using an S2X-editor. editor The Web Dynpro runtime loads property resource bundles depending on a determined session locale. An application developer can access locale-dependant texts via
IWDTextAccessor-API: wdComponentAPI.getTextAccessor() IWDTextAccessor IMessage<Component>: Message texts of type error, warning, <Component> standard
Deployable Project
en
de
different locales
XLF-files can be edited using the S2X-Document-Editor of the SAP NetWeaver Developer Studio.
xlf file
SAP AG 2004, SAP TechEd / PRTL351 / 62
In SAP NetWeaver 04 the S2X-editor can be used for translating texts in copied and renamed ( with _<locale>) XLF-files. In NetWeaver 04 a R/3-based translation process is not possible on customer side. Upcoming integration scenarios will offer an authoring environment for translating S2X-files in the SAP NetWeaver Developer Studio.
Please note that this document is subject to change and may be changed by SAP at any time without notice. The document is not intended to be binding upon SAP to any particular course of business, product strategy and/or development.
SAP AG 2004, SAP TechEd / PRTL351 / 63
Translation of XLF-Files
Web Dynpro Component
Devleoper
The translation workflow returns locale-dependant XLFfiles for every initial XLF-file. These files end with _<locale> before the file-extension xlf .
different locales Web Dynpro Tools transfer texts into property files
xlf file
Component
create archive
xlf file
All locale-dependant texts of a simple type contained in the local Java Dictionary are stored in a corresponding XLF-File: xlf file <Simple Type Name>.dtsimpletype_de.xlf <Simple Type Name>.dtsimpletype_en.xlf <Simple Type Name>.dtsimpletype_xlf
xlf file View View View View Controller Window Window Messages and Texts
View
S2X Editor
Window
S2X Editor
IMessage<Component> Web Dynpro Controller IWDTextAccessor ISimpleType Deployed Project Web Dynpro Runtime Locale-dependant texts stored in property resource bundles can be accessed from within a Web Dynpro controller via the interfaces IMessage<Component>, IWDTextAccessor and ISimpleType .
SAP AG 2004, SAP TechEd / PRTL351 / 72
IMessage<Component>
All Messages of type standard, warning or error are added as Constants of type IWDMessage to the generated Interface IMessage<Compo- nent Name>.java. Name>.java Every Web Dynpro component has its own message interface IMessage<Component Name>.java. Name>.java Messages of type text are accessible via the IWDTextAccessor-API. IWDTextAccessor
SAP AG 2004, SAP TechEd / PRTL351 / 73
IMessage<Component>
public void checkMandatory( java.lang.String fieldName ) { //@@begin checkMandatory() IWDMessageManager messageMgr = wdComponentAPI.getMessageManager(); ... messageMgr.reportContextAttributeMessage( wdContext.currentContextElement(), attributeInfo, IMessageSimpleErrors.MISSING_INPUT, IMessageSimpleErrors.MISSING_INPUT new Object[] { fieldLabel }, true); //@@end }
IWDTextAccessor Messages of type text cannot be displayed by the Web Dynpro Message Manager. They are defined for externalizing texts from controller coding. All message texts defined in the message pool can be accessed with the IWDTextAccessor-API associated to the IWDComponent IWDTextAccessor interface:
IWDTextAccessor textAcc = wdComponentAPI.getTextAccessor()
In contrast to messages of type standard, warning and error messages of type text are not addressable via generated constants. Instead the message keys have to be passed to the IWDTextAccessorAPI as String values.
The locale of a Web Dynpro application within a project can be configured by setting the pre-defined application property sap.locale . The application language is used by the Web Dynpro runtime as session locale in case no user locale and no browser locale are specified.
Web Dynpro Component A Deprecated Web Dynpro Only needed in older Component B versions where no texts Web Dynpro can be added to the Tools message pool
Local Dictionary Externalize Strings
different locales
Build
Custom property resource bundles containing key-value-pairs can be read using the Web Dynpro Sservice WDResourceHandler. WDResourceHandler
start application
en
Web Dynpro UI
pt de en fr it ru
The class java.lang.ResourceBundle loads property files for the calculated WD session locale. If no resource bundle for this locale exists the default resource bundle <name>.properties is loaded.
* URL parameter sap-locale
SAP AG 2004, SAP TechEd / PRTL351 / 83
Summary Web Dynpro Internationalzation Web Dynpro Internationlization is based on externalizing texts from controller code and metadata files into property resource bundles. For translation purposes XLF-Files are additionally created. Accessing locale-dependant texts from inside Web Dnypro controllers is based on the interfaces IMessage<Component Name> and IWDTextAccessor. Web Dynpro determines the session locale of a startet Web Dynpro application based on a predefined fall-back mechanism.
Exercise
Dynamic UI Generation Web Dynpro Debugging Web Dynpro Internationalization Object Value Selector
IWDOVSContextNotificationListener IWDOVSContextNotificationListener
OVS-related Contexts
Application Context
View Context
Root Node 0..1 Flight AirlineId DepCity ArrCity 0..n
Input
Airline
OVS UI needs dictionary metadata (e.g. field labels and column headers) Context attributes have to be properly typed for the generic OVS UI
Output
Lufthansa
Arrival
Bonn
-addOVSExtension( -addOVSExtension( IWDAttributeInfo[] startupAttributes, IWDAttributeInfo[] startupAttributes, IWDNode queryInputNode, // lead selection pointing to element IWDNode queryInputNode, // lead selection pointing to element IWDNode queryResultNode, // caridinality 0..n IWDNode queryResultNode, // caridinality 0..n IWDOVSContextNotificationListener queryListener) IWDOVSContextNotificationListener queryListener)
Provides context attributes (startupAttributes) with OVS functionality. Uses separate context nodes for storing search query input values (queryInputNode, lead selection points to node element) and search query results (queryOutputNode, 0..n). Uses a query listener class (queryListener) implementing IWDOVSContextNotificationListener for performing the search query and copying context data between OVS and the application.
The OVS listeners hook methods can be seen as event handlers called at three points of time:
OVSListener OVSListener
View Controller
OVS Listener
add OVS Extension to context attributes Request OVS Service Request Specify Search and Press Go OVS Action call OVS-Listener hook applyInputValues()
Select Result
OVS Action
SAP AG 2004, SAP TechEd / PRTL351 / 94
data binding
View Context
Root Node 0..1 Flight AirlineId DepCity ArrCity
OVS
applicationNodeElement
data binding
OVS
View Context
Root Node Flight 0..1
LH
OVS
OVSSearchOuput 0..n
OVS
OVSSearchOuput 0..n
OVS
execute RFC
OVSSearchOuput 0..n
OVS
OVSSearchOutput
0
0..n
1 LH LH
n LH
Bonn
New York
London
OVS
View Context
Root Node Flight 0..1
LH FRA New York
OVSSearchOutput
0
0..n
1 LH LH
n LH
Bonn
New York
London
OVS
Direct Usage of Model Nodes as OVS Input/Output Nodes Best Solution: Use OVS-adapted RFCs with input model classes containing all needed query properties and output model classes containing all needed result properties (no independent helper input/ouput nodes required).
OVS
OVS Input Node
0..1
Output Flight_List
LH Bonn
0..n
Exercise
Further Information
Public Web:
www.sap.com SAP Developer Network: www.sdn.sap.com Web Application Server Web Dynpro SAP Developer Network: www.sdn.sap.com Web Application Server Web Dynpro Web Dynpro Articles Debugging a Web Dynpro Application Debugging ABAP Code from within Web Dynpro Applications SAP Customer Services Network: www.sap.com/services/
Questions?
Q&A
SAP AG 2004, SAP TechEd / PRTL351 / 111
Feedback
Please complete your session evaluation. Be courteous deposit your trash, and do not take the handouts for the following session.
Thank You !