
To create a Web Dynpro component that can be exposed as a callable object in Guided Procedures (GP), you must implement the IGPWebDynproCO interface. It enables the execution of the component in the context of a GP process.
For more information about the interfaces used for the implementation, see the API documentation at http://www.sdn.sap.com/irj/sdn/javadocs.
You must have added all required dependencies.
For more information, see Creating and Configuring the Web Dynpro Project .
Create a Web Dynpro Component
Enter a name for the component - for example, CUserDetails . Enter a package name - for example, com.sap.examples.wdpco .
Deselect the option Default Window and Views, select Implemented Interfaces and choose Next.
Confirm your choice with Finish.
Edit the Component Controller Implementation
For this example, you define the following attributes:
Methods execute and getDescription are inherited from interface IGPWebDynproCO .
//@@begin others private IGPExecutionContext executionContext; private IWDTextAccessor textAccessor; private GPWebDynproResourceAccessor resourceAccessor; //@@end |
This method returns the technical description of the callable object that contains metadata for the object's input, output, and configuration parameters, as well as for its result states.
Using the coding example below, you:
Invocation exception occurs if the technical names contain forbidden characters (only numbers, Latin letters, and underscore are allowed).
In the example, the method returns null if there is an error.
To log the error message, you use an instance of com.sap.tc.logging.Location , which is automatically available in Web Dynpro.
publiccom.sap.caf.eu.gp.co.api.IGPTechnicalDescription getDescription(java.util.Locale locale) {//@@begin getDescription() try{IGPTechnicalDescriptiontechnicalDescription = GPCallableObjectFactory.createTechnicalDescription( "CO_NAME", "CO_DESCRIPTION", resourceAccessor, locale); // Pre-existing input structure IGPStructureInfoinput = technicalDescription.getInputStructureInfo(); IGPAttributeInfo userId = input.addAttribute("UserID", IGPAttributeInfo.BASE_STRING);userId.setMultiplicity(IGPAttributeInfo.MULITIPLICITY_1_1); //Pre-existing structure for output parameters IGPStructureInfooutput = technicalDescription.getOutputStructureInfo(); //Create the attributes in the output structure IGPStructureInfouserStructure = output.addStructure("User");userStructure.addAttribute( "firstName", IGPAttributeInfo.BASE_STRING); userStructure.addAttribute( "lastName", IGPAttributeInfo.BASE_STRING); userStructure.addAttribute("phone", IGPAttributeInfo.BASE_STRING); userStructure.addAttribute("fax", IGPAttributeInfo.BASE_STRING);//add result state IGPCOResultStateInfosuccess = technicalDescription.addResultState("Success"); success.setDescriptionKey("Success_desc"); return technicalDescription; } catch (GPInvocationException e) {logger.logT( Severity.ERROR, Category.APPLICATIONS, "Incorrect technical name"); logger.traceThrowableT( Severity.ERROR, "Exception while creating technical description: ", e); return null; } //@@end } |
In this method, you can implement any functions that the callable object should execute. For example, you can process the input parameters, if any, interact with the system, and so on.
To retrieve the object parameters, you use the execution context.
In the example below, the method parses the input parameter (user ID), and searches user management for the relevant user. Then it retrieves the user details, such as first and last name, phone and fax numbers. The values are then assigned to the relevant context attributes.
If there is an invocation or UME error, the method logs a technical exception.
publicvoid execute( com.sap.caf.eu.gp.co.api.IGPExecutionContext executionContext ) {//@@begin execute() String userId = null; try {this.executionContext = executionContext; //Process the input parameters IGPStructureinput = executionContext.getInputStructure(); userId = (String) input.getAttributeAsString("UserID");wdContext.currentContextElement().setUserId(userId); //Retrieve user data IUserFactory factory = UMFactory.getUserFactory(); IUser user = factory.getUserByLogonID(userId); String lastName = user.getLastName(); String firstName = user.getFirstName(); String phone = user.getTelephone(); String fax = user.getFax(); //Set the new values in the context IGPStructureoutput = executionContext.getOutputStructure(); wdContext.currentContextElement().setAttributeValue( "firstName", firstName); wdContext.currentContextElement().setAttributeValue( "lastName", lastName); wdContext.currentContextElement().setAttributeValue("phone", phone); wdContext.currentContextElement().setAttributeValue("fax", fax); } catch (GPInvocationException e) { String localizedMessage = textAccessor.getText("ERROR_GETTING_PARAMETERS");wdThis.wdFireEventTechnicalException( newGPTechnicalCallableObjectException( logger, localizedMessage, e)); } catch (UMException ex) { String localizedMessage = textAccessor.getText("USER_NOT_FOUND", new Object[]{userId});wdThis.wdFireEventTechnicalException( newGPTechnicalCallableObjectException( logger, localizedMessage, ex)); } //@@end } |
In this method you complete the execution of the callable object. For example, you can set the result state and the output parameters.
Finally, you must call the execution context method processingComplete() to indicate that the callable object has been executed.
Technical exception is used to process the errors that might occur.
publicvoid complete( ) {//@@begin complete() try {IGPStructure output = executionContext.getOutputStructure(); //Set the values of the output parameters IGPStructure user = output.addStructure("User"); user.setAttributeValue("firstName", wdContext.currentContextElement().getFirstName()); user.setAttributeValue("lastName", wdContext.currentContextElement().getLastName()); user.setAttributeValue("phone", wdContext.currentContextElement().getPhone());user.setAttributeValue( "fax", wdContext.currentContextElement().getFax()); executionContext.setResultState("Success");executionContext.processingComplete(); } catch (GPInvocationException e) { String localizedMessage = textAccessor.getText("ERROR_SETTING_PARAMETERS");wdThis.wdFireEventTechnicalException( newGPTechnicalCallableObjectException( logger, localizedMessage, e)); } catch (GPEngineException e) { String localizedMessage = textAccessor.getText("INTERNAL_ERROR");wdThis.wdFireEventTechnicalException( newGPTechnicalCallableObjectException( logger, localizedMessage, e)); } //@@end } |
The technical name of the callable object, as well as the technical names of its parameters and result states, is also available as keys that you can add to the message pool.
You can define additional keys to localize error messages, as well as result state descriptions, as shown in the coding examples above.
You add message text for the message keys manually in the message pool.
For more information, see Message Editor .
To access the texts from the message pool, you need an instance of GPWebDynproResourceAccessor .
publicvoid wdDoInit() {//@@begin wdDoInit() IWDTextAccessor textAccessor = wdComponentAPI.getTextAccessor(); GPWebDynproResourceAccessor resourceAccessor =newGPWebDynproResourceAccessor(textAccessor); //@@end } |
Create the User Interface
Select CUserDetails - com.sap.examples.wdpco.
publicvoid onActionComplete(com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent ) {//@@begin onActionComplete(ServerEvent) wdThis.wdGetCUserDetailsController().complete(); //@@end } |
Define an input field for each attribute that you want to display, and map its value to the relevant context attribute.
Create a button, and assign value Complete to its onAction property.
4. Build and Deploy the Component
Check for errors and warnings in view Infrastructure Console view.
If you have not created an archive for your DC, you will be prompted to do so. Select Make consistent first (Create archive) and choose OK.
You have implemented and deployed a Web Dynpro component that can be executed within a GP process.
Your next step is to expose the component as a callable object in GP design time.
More information: Creating an Instance of the Callable Object