Show TOC Start of Content Area

Procedure documentation Implementing Web Dynpro Callable Objects  Locate the document in its SAP Library structure

Use

Using Web Dynpro for Java, you can implement custom callable objects that provide a user interface.

Prerequisites

·        You must be familiar with the basics of programming with Web Dynpro for Java.

      You have set up your project as described in Setting Up Your Project.

In addition to the required development components, you must also add dependency to caf/eu/gp/api/wd (public part GPWebDynproCO) in software component GP-CORE.

      You have added IGPWebDynproCO (com.sap.caf.eu.gp.co.api.IGPWebDynproCO) to the list of implemented interfaces.

Procedure

1. Implement the Design Time Aspects of the Callable Object

For the design-time part of the Web Dynpro callable object, you must implement the getDescriptionmethod of the IGPWebDynproCO interface. To do that, in the interface controller of the Web Dynpro component:

...

       1.      Create the technical description of the object.

Use the method createTechnicalDescription() of the class com.sap.caf.eu.gp.co.api.GPCallableObjectFactory. As parameters, enter the keys to the localizable name and description of the object, as well as a reference to a resource accessor instance, and the original locale.

Example

try {

 

         IGPTechnicalDescription technicalDescription =

            GPCallableObjectFactory.createTechnicalDescription(

               "CO_NAME",

               "CO_DESCRIPTION",

               resourceAccessor,

               locale);

...

       2.      Define the input and output parameters.

You define the input and output parameters of the Web Dynpro callable object as sub-nodes of predefined empty root structures.

                            a.      To retrieve these structures, you use the methods getInputStructureInfo() and getOutputStructureInfo() of the interface com.sap.caf.eu.gp.co.api.IGPTechnicalDescription respectively.

They return an instance of the interface com.sap.caf.eu.gp.co.api.IGPStructureInfo, which you use to define the input and output parameters.

                            b.      Use the methods addStructure or addAttribute of the IGPStructureInfo interface to define a new parameter structure or a single attribute.

                            c.      Set the properties of the parameter structures or attributes.

For both structures and attributes you must set the multiplicity. It defines whether the parameter is required and whether it is a list. For structures you use the constants defined in IGPStructureInfo, and for individual attributes – the ones in com.sap.caf.eu.gp.co.api.IGPAttributeInfo.

Example

IGPStructureInfo input =

            technicalDescription.getInputStructureInfo();

 

IGPAttributeInfo userId =

            input.addAttribute("UserID", IGPAttributeInfo.BASE_STRING);

       3.      Define the configuration parameters.

You may define string, integer, Boolean, or MIME type configuration parameters. The default type is string. You can create a configuration parameter that exposes a list of predefined values.

To create a configuration parameter, use the method addConfigurationAttribute of the interface IGPTechnicalDescription.

Example

IGPConfigAttributeInfo configParam = technicalDescription.addConfigurationAttribute("e-mail");

       4.      Define the result states for completing the callable object’s execution.

You must define at least one result state that you can set when you complete the object’s execution. You can define additional result states if the object’s execution may have more than one result.

To add a result state, use the IGPTechnicalDescription interface method addResultState.

Example

IGPCOResultStateInfo success =

            technicalDescription.addResultState("Success");

       5.      Finally, define process exceptions.

You may define specific process exceptions for the callable object. They are related to the functionality implemented in the component, and enable you to include the exception processing as a part of the process flow at runtime using the exception handling mechanisms at block level.

Example

IGPExceptionInfo processExc = technicalDescription.addProcessException("USER_NOT_FOUND");

2. Implement the Runtime Logic of the Object

...

       1.      Read the input and set the values of the output parameters.

You read the input and set the output in the execute method of the IGPWebDynproCO interface, using the methods of the interface com.sap.caf.eu.gp.co.api.IGPExecutionContext.

To retrieve the runtime representation of the input structure, you call the method getInputStructure of the execution context. Then you can work with the attributes in the structure using the methods of the interface com.sap.caf.eu.gp.co.api.IGPStructure.

To set the output parameters, you retrieve the output structure using the method getOutputStructureof the execution context. Then you can add sub-structures to the root output structure, and set the values of the output parameters using the method addAttributeValue of the IGPStructure interface.

Note

You can use context attributes to store the values of the object’s parameters while operating with them.

Example

this.executionContext = executionContext;

//Process the input parameters  

IGPStructure input = executionContext.getInputStructure();

userId = (String) input.getAttributeAsString("UserID");

wdContext.currentContextElement().setUserId(userId);

//Retrieve user data

IUserFactory factory = UMFactory.getUserFactory();

IUser user = factory.getUserByLogonID(userId);

String firstName = user.getFirstName();

//Set the new values in the context

IGPStructure output = executionContext.getOutputStructure();

wdContext.currentContextElement().setAttributeValue(

   "firstName", firstName);

       2.      Complete the processing of the callable object.

You must define an additional method in the component’s interface controller, which you use to call the execution context processingComplete method, and to set the relevant result state. If you have defined multiple result states, you should create multiple methods, so that you can implement the required logic and set the relevant result state for each possible scenario.

Example

IGPStructure user = output.addStructure("User");

user.setAttributeValue(

            "firstName",

            wdContext.currentContextElement().getFirstName());

         executionContext.setResultState("Success");

         executionContext.processingComplete();

       3.      Set up the exception handling mechanisms.

If you have defined any process exceptions, set them appropriately when completing the process.

In addition, make sure that you throw com.sap.caf.eu.gp.exception.api.GPTechnicalCallableObjectException with a localized message as a parameter to process any technical errors that might occur.

Example

} catch (GPInvocationException e) {

 

         String localizedMessage =

            textAccessor.getText("ERROR_SETTING_PARAMETERS");

 

         wdThis.wdFireEventTechnicalException(

            new GPTechnicalCallableObjectException(

               logger,

               localizedMessage,

               e));

3. Implement Localization

Web Dynpro provides a built-in resource accessor, which you can use for your localizable texts. GP extends that standard Web Dynpro interface and provides a class that enables you to use the message pool – com.sap.caf.eu.gp.co.api.GPWebDynproResourceAccessor.

To implement localization:

...

       1.      Enter key and value pairs in the message pool for all parameters that you want to localize.

Use the key to access the relevant parameter in your code.

       2.      Instantiate the GPWebDynproResourceAccessor using an instance of the IWDResourceAccessor, which is automatically available in the Web Dynpro component.

       3.      Use the GPWebDynproResourceAccessor instance to create the technical description of the callable object.

To retrieve the localized message texts, you can use the getText() method of the generic Web Dynpro resource accessor.

Example

IWDTextAccessor textAccessor = wdThis.wdGetAPI().getComponent().getTextAccessor();

GPWebDynproResourceAccessor resourceAccessor = new                           GPWebDynproResourceAccessor(textAccessor);

4. Implement the User Interface

...

       1.      Create a new view for the Web Dynpro component.

       2.      Define events for the methods in the Web Dynpro interface controller that you want to call from the UI.

       3.      Implement the event handlers for each event, so that they call the relevant methods from the interface controller.

       4.      Create UI elements, such as buttons, and link each of them to an event that you have created. 

Result

You can build your DC and deploy it to the Java server.

Next, you must expose the Web Dynpro component as a callable object in the GP design time.

More information: Exposing Web Dynpros as Callable Objects

Example

For an example of a Web Dynpro callable object, see Implementing and Exposing a Web Dynpro as a Callable Object.

 

 

End of Content Area