
Using Web Dynpro for Java, you can implement custom callable objects that provide a user interface.
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.
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 getDescription method of the IGPWebDynproCO interface. To do that, in the interface controller of the Web Dynpro component:
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.
try{IGPTechnicalDescription technicalDescription = GPCallableObjectFactory.createTechnicalDescription( "CO_NAME", "CO_DESCRIPTION", resourceAccessor, locale); ... |
You define the input and output parameters of the Web Dynpro callable object as sub-nodes of predefined empty root structures.
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.
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 .
IGPStructureInfoinput = technicalDescription.getInputStructureInfo(); IGPAttributeInfouserId = input.addAttribute("UserID", IGPAttributeInfo.BASE_STRING); |
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 .
IGPConfigAttributeInfoconfigParam = technicalDescription.addConfigurationAttribute("e-mail"); |
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 .
IGPCOResultStateInfosuccess = technicalDescription.addResultState("Success"); |
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.
IGPExceptionInfoprocessExc = technicalDescription.addProcessException("USER_NOT_FOUND"); |
2. Implement the Runtime Logic of the Object
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 getOutputStructure of 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.
You can use context attributes to store the values of the object's parameters while operating with them.
this.executionContext= executionContext; //Process the input parameters IGPStructureinput = executionContext.getInputStructure(); userId= (String) input.getAttributeAsString("UserID");wdContext.currentContextElement().setUserId(userId); //Retrieve user data IUserFactoryfactory = UMFactory.getUserFactory(); IUseruser = factory.getUserByLogonID(userId); StringfirstName = user.getFirstName(); //Set the new values in the context IGPStructureoutput = executionContext.getOutputStructure(); wdContext.currentContextElement().setAttributeValue( "firstName", firstName); |
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.
IGPStructureuser = output.addStructure("User");user.setAttributeValue( "firstName", wdContext.currentContextElement().getFirstName()); executionContext.setResultState("Success");executionContext.processingComplete(); |
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.
}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:
Use the key to access the relevant parameter in your code.
To retrieve the localized message texts, you can use the getText() method of the generic Web Dynpro resource accessor.
IWDTextAccessor textAccessor= wdThis.wdGetAPI().getComponent().getTextAccessor(); GPWebDynproResourceAccessor resourceAccessor = new GPWebDynproResourceAccessor(textAccessor); |
4. Implement the User Interface
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
For an example of a Web Dynpro callable object, see Implementing and Exposing a Web Dynpro as a Callable Object .