Technology Blog Posts by Members
cancel
Showing results for 
Search instead for 
Did you mean: 
former_member4529
Active Contributor
0 Likes
1,017

Developing Web Dynpro Java callable object implementing the GP Interface in Netweaver CE has been significantly changed from Netweaver 7.0(04s). Unlike Netweaver 7.0 the Interface controller is not used anymore to implement the GP interface methods. Those are implemented in the component controller. I'll explain here the steps to implement the callable object in a Web Dynpro application in Netweaver CE.

Create a new Web Dynpro DC (local or NWDI based). Select the project right-click and select Development Component -> Show in Component Navigator.

Select the Web Dynpro component just created in the component navigator and right-click and select the option Add DC Dependency.

Select com.sap.security.api.sda from SC ENGINEAPI and caf/eu/gp/api and caf/eu/gp/api/wd from GP-CORE.

Click Next and select Design Time, Deploy Time and Run Time dependency for all the three DCs.

Click on Finish. Now create a new component. Uncheck the options Default Windows and Views and select the option Implemented Interfaces.

Click on Next. In the next screen click on Add on Implemented Component Interfaces section and select IGPWebDynproCO interface to implement.

A new window gets created which is mapped with the interface view WebDynproCOInterfaceView. Click on Finish. A dialog displays the objects created by implementing the GP interface.

Click on Ok and open the component controller. Two methods of the GP interface execute() and getDescription() have got created there which should be implemented.

To implement GP interface methods add the following declaration in the "others" section at the end of the component controller.

//@@begin others
   private IGPExecutionContext executionContext;
   private IWDTextAccessor textAccessor;
//@@end

In the getDescription() method the input and output parameters of the callable object should be declared.

public com.sap.caf.eu.gp.co.api.IGPTechnicalDescription getDescription(java.util.Locale locale)
  {
    //@@begin getDescription()





    try {
         this.textAccessor = wdComponentAPI.getTextAccessor();





         GPWebDynproResourceAccessor resourceAccessor = new GPWebDynproResourceAccessor(textAccessor);        
         IGPTechnicalDescription technicalDescription =  GPCallableObjectFactory.createTechnicalDescription("CO_NAME", "CO_DESCRIPTION",
                                                                                   resourceAccessor, locale);
          // Pre-existing input structure
         IGPStructureInfo input = technicalDescription.getInputStructureInfo();
         IGPAttributeInfo param1 = input.addAttribute("Param1", IGPAttributeInfo.BASE_STRING);
         param1.setMultiplicity(IGPAttributeInfo.MULITIPLICITY_1_1);
         //Pre-existing structure for output parameters
         IGPStructureInfo output = technicalDescription.getOutputStructureInfo();
          //Create the attributes in the output structure
         IGPStructureInfo outputStructure = output.addStructure("OutputStructure");
         outputStructure.addAttribute("OPParam1", IGPAttributeInfo.BASE_STRING);
         outputStructure.addAttribute("OPParam2", IGPAttributeInfo.BASE_STRING);
           //add result state
         IGPCOResultStateInfo approve = technicalDescription.addResultState("Approve");
         approve .setDescriptionKey("Request Approved");  
         IGPCOResultStateInfo reject = technicalDescription.addResultState("Reject");
         reject.setDescriptionKey("Request Rejected");  
         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 the above method the input and output structures of the GP callable object is defined. The input and output can have both single parameter or structure as well. The cardinality of the structure can also be specified here. For more details on how to define the multi-cardinality GP parameters refer this blog : How To Pass Multiple Line Items Data Between Web Dynpro Java Callable Objects in GP.

In the execute() method implement the logic for callable object execution in GP context.

public void execute( com.sap.caf.eu.gp.co.api.IGPExecutionContext executionContext )
  {
    //@@begin execute()
      String param1 = null;
      try {
         this.executionContext = executionContext;
 
         //Process the input parameters   
         IGPStructure input = executionContext.getInputStructure();
         param1 = (String) input.getAttributeAsString("Param1");
         wdContext.currentContextElement().setParam1(param1); 
 
         //implement any addtional logic
 
      } catch (GPInvocationException e) {
         String localizedMessage = textAccessor.getText("ERROR_GETTING_PARAMETERS"); 
         wdThis.wdFireEventTechnicalException(
            new GPTechnicalCallableObjectException(
               logger,
               localizedMessage,
               e));
      } 
     //@@end
 }

In the above method the input parameter is read from the GP context and set the values in the Web Dynpro context as required.

Also implement another method in the component controller to complete the step execution.

public void complete( )
  {
    //@@begin complete()
      try {
         IGPStructure output = executionContext.getOutputStructure();
 
         //Set the values of the output parameters
         IGPStructure opStructure = output.addStructure("OutputStructure");            
         opStructure.setAttributeValue("OPParam1", wdContext.currentContextElement().getOPParam1());
         opStructure.setAttributeValue("OPParam2", wdContext.currentContextElement().getOPParam2());
         executionContext.setResultState("Approve");
         executionContext.processingComplete();
 
      } catch (GPInvocationException e) {
         String localizedMessage = textAccessor.getText("ERROR_SETTING_PARAMETERS"); 
         wdThis.wdFireEventTechnicalException(
            new GPTechnicalCallableObjectException(
               logger,
               localizedMessage,
               e));
      } catch (GPEngineException e) {
         String localizedMessage = textAccessor.getText("INTERNAL_ERROR"); 
         wdThis.wdFireEventTechnicalException(
            new GPTechnicalCallableObjectException(
               logger,
               localizedMessage,
               e));
      }
    //@@end
 }
 

In the above method the output structure of the GP context is set with the values from the Web Dynpro context node and the resultstate of the callable object is also set. Call this method from an action of the Web Dynpro view e.g. a complete button when the step execution needs to be completed.

Once a Web Dynpro Java component is implemented as a GP callable object implementing the GP interface it cannot be tested as a stand-alone application as no interface views are available. To test the Web Dynpro application create a new callable object in GP design time of type Web Dynpro Java (GP Interface) and select the Web Dynpro component after build and deploy. Test it from the callable object test environment in GP design time.

8 Comments