Show TOC Start of Content Area

Object documentation WDCODisplaySelectItems  Locate the document in its SAP Library structure

Definition

A Web Dynpro component that displays a list of available office items, and enables purchasers to select one or more of them.

Use

This component is displayed if the user chooses to select the required items from a list in the first step of the Order Office Material process.

Structure

The following aspects of the component’s structure are relevant for its implementation:

     Basic data (such as name, package, and so on)

     Component controller

     Interface controller

     User interface

Basic Data

Name

WDCODisplaySelectItems

Package

com.sap.caf.eu.gp.example.ordermat.wdco.displayselect

Implemented Interfaces

IGPWebDynproCO (com.sap.caf.eu.gp.co.webdynpro)

Used Web Dynpro Components

CContext (com.sap.caf.eu.gp.example.ordermat.wdco)

Note

This is a helper component for this example that holds the example data. The component is not described in the documentation, because its implementation is not GP-specific. In a real-life scenario, the data will be retrieved from a real repository, such as a database, or a backend system.

 

Component Controller

The WDCODisplaySelectItems component controller implements the functionality that the component provides.

Properties

The interface controllers of the following components are required:

     CContext

     WDCODisplaySelectItems

Component Controller: Properties

This graphic is explained in the accompanying text

Context

The context of the component controller contains a structure – ExampleData, with value attributes defined for each attribute of the office items:

     name

     orderNumber

     price

     currency

     unit

In addition, a value attribute priceAsString is defined to represent the price of the office items converted into string.

The whole ExampleData structure, as well as each attribute (excluding priceAsString) is mapped to the relevant value attribute in the CContext’s interface controller context, so that the values are taken from CContext.

Component Controller: Context

This graphic is explained in the accompanying text

Methods

The following methods are declared:

     execute (com.sap.caf.eu.gp.context.api.IGPExecutionContext context) – the method is used in the implementation of the execute method in the interface controller (see section Interface Controller)

     createDescription (java.util.Locale locale) – the method is used in the implementation of the getDescription method in the interface controller (see section Interface Controller)

     addItem () – the method is used in the implementation of the onActionOrderItemevent in view VDisplaySelectItems (see section User Interface)

Component Controller: Methods

This graphic is explained in the accompanying text

Implementation

The implementation of the component controller implies adding the relevant logic in the methods that are declared:

     Implementing method createDescription()

This method returns an instance of the com.sap.caf.eu.gp.co.api.IGPTechnicalDescription interface. It defines the attributes of a callable object based on this Web Dynpro component.

The technical description includes:

     Basic data

The basic data for the callable object comprises its name, description, locale and resource accessor. These are supplied as parameters when the technical description is instantiated. The name and the description can be localized.

Localization is enabled using an instance of GPWebDynproResourceAccessor.

     Input parameters

The input parameters are defined as children of the root structure input, which exists by default. You can add both sub-structures and individual parameters. To do that, you use the com.sap.caf.eu.gp.structure.api.IGPStructureInfo interface, and its methods addStructure() and addAttribute().

For this component, a sub-structure is added, whose value is retrieved from the CContext component. The multiplicity of the structure is 0...n, which means that the structure is a list and may be empty. It represents the attributes of an office item.

The attributes themselves are also added to the root input structure, and their values are also retrieved from the CContext component.

     Output parameters

Output parameters are defined in the same way as input parameters. They are added to the predefined output root structure.

In this component, the output parameters are the same as the input.

     Result states

The result state of a callable object indicate the outcome of the callable object execution. It is a convenient way to manage the process flow at runtime, as you can define what action is executed next according to the result state reached. You can define an arbitrary number of result states for the callable object. To do that, you use the technical description method addResultState().

For this component, a result state RESULT_STATE_COMPLETED is defined. Optionally, a localized description can be added as well.

Method createDescription()

public com.sap.caf.eu.gp.co.api.IGPTechnicalDescription createDescription( java.util.Locale locale )

  {

    //@@begin createDescription()

   IGPTechnicalDescription technicalDescription;

  

    //create resource accessor

   IWDTextAccessor textAccessor = wdComponentAPI.getTextAccessor();

   GPWebDynproResourceAccessor resourceAccessor = new GPWebDynproResourceAccessor(textAccessor);

 

   technicalDescription = GPCallableObjectFactory.createTechnicalDescription(

         "CO_TEXT",

         "CO_DESC",

         resourceAccessor,

         locale);

  

   try {

      //INPUT:

      //get root input

      IGPStructureInfo input = technicalDescription.getInputStructureInfo();

     

      //add item structure to root input 

      IGPStructureInfo inputItemStructureInfo = input.addStructure(CContextInterface.STRUCTURE_ITEMS);

      inputItemStructureInfo.setMultiplicity(IStructureInfo.MULITIPLICITY_0_N);

  

      IGPAttributeInfo attributeInfo = null;   

     

      //add attributes to item structure 

      inputItemStructureInfo.addAttribute(CContextInterface.PARAM_ORDER_NUMBER, IGPAttributeInfo.BASE_STRING);

      inputItemStructureInfo.addAttribute(CContextInterface.PARAM_NAME, IGPAttributeInfo.BASE_STRING);

      inputItemStructureInfo.addAttribute(CContextInterface.PARAM_UNIT, IGPAttributeInfo.BASE_STRING);

      inputItemStructureInfo.addAttribute(CContextInterface.PARAM_CURRENCY, IGPAttributeInfo.BASE_STRING);

      inputItemStructureInfo.addAttribute(CContextInterface.PARAM_PRICE, IGPAttributeInfo.BASE_DOUBLE);

     

      //OUTPUT:

      //get root output

      IGPStructureInfo output = technicalDescription.getOutputStructureInfo();

           

      //add item structure to root output

      IGPStructureInfo outputItemStructureInfo = output.addStructure(CContextInterface.STRUCTURE_ITEMS);

      outputItemStructureInfo.setMultiplicity(IGPStructureInfo.MULITIPLICITY_0_N);

     

      //add attributes to item structure

      outputItemStructureInfo.addAttribute(CContextInterface.PARAM_ORDER_NUMBER, IGPAttributeInfo.BASE_STRING);

      outputItemStructureInfo.addAttribute(CContextInterface.PARAM_NAME, IGPAttributeInfo.BASE_STRING);

      outputItemStructureInfo.addAttribute(CContextInterface.PARAM_UNIT, IGPAttributeInfo.BASE_STRING);

      outputItemStructureInfo.addAttribute(CContextInterface.PARAM_CURRENCY, IGPAttributeInfo.BASE_STRING);

      outputItemStructureInfo.addAttribute(CContextInterface.PARAM_PRICE, IGPAttributeInfo.BASE_DOUBLE);

  

   } catch (GPInvocationException e) {

  

   //exception handling

      String localizedMessage = m_TextAcc.getText("ERROR_CREATING_TECHNICAL_DESC");

 

   wdThis.wdGetWDCODisplaySelectItemsInterfaceController().wdFireEventTechnicalException(new GPTechnicalCallableObjectException(logger, localizedMessage, e));

   }

     

   //result states

   IGPResultStateInfo success = technicalDescription.addResultState(RESULT_STATE_COMPLETED);

   success.setDescriptionKey("RESULTSTATE_COMPLETED_DESC");  

     

   return technicalDescription;

    //@@end

  }

     Implementing method execute()

The framework calls this method when the callable object is executed as a part of a process at runtime. The method implementation includes retrieving the input data. In this component, the input structures are mapped to the output structures, so that the data can be passed on to the next action in the process. This is implemented using the private method mapInputToOutputData().

The programmatic parameter mapping is required because this callable object is used in a loop block, and the mapping guarantees that all selected items will eventually be added to the output, and not only the last selected one.

Method execute()

public void execute( com.sap.caf.eu.gp.context.api.IGPExecutionContext context )

  {

    //@@begin execute()

    m_context = context;       

    this.mapInputDataToOutputData(context);  

   

   //format price for ui

    for(int i=0, size=wdContext.nodeExampleData().size(); i<size; i++){

      IPublicWDCODisplaySelectItems.IExampleDataElement exampleDataElement = wdContext.nodeExampleData().getExampleDataElementAt(i);

      double price = exampleDataElement.getPrice();

      String priceAsString = new DecimalFormat("#0.00").format(price);

      exampleDataElement.setPriceAsString(priceAsString);     

    }

    //@@end

  }

     Implementing method addItem()

This method is invoked when the user selects a specific item from the list, and chooses to order it. It is the method that completes the callable object execution.

The method assigns the attribute values of the selected item to the output parameters of the callable object. For that purpose, the com.sap.caf.eu.gp.structure.api.IGPStructure interface is used. While the IGPStructureInfo interface describes the structure parameters, the IGPStructure interface represents them at runtime.

To set the actual value of an attribute, you retrieve the root output structure, and then use method addStructure() to add a sub-structure, and setAttributeValue()to set the value. In this case, the sub-structures and the attribute values are retrieved from the CContext component.

Finally, the result state is set, and the processing completion is indicated to the framework by calling the processingComplete() method of the execution context.

Method addItem()

public void addItem()

  {

    //@@begin addItem()

   try {

      //get current context element

      IPublicWDCODisplaySelectItems.IExampleDataElement exampleDataElement = wdContext.nodeExampleData().currentExampleDataElement();

     

      //get root output

      IGPStructure output = m_context.getOutputStructure();

     

      //set values of output parameters       

      IGPStructure outputItemStructure = output.addStructure(CContextInterface.STRUCTURE_ITEMS);  

     

      outputItemStructure.setAttributeValue(CContextInterface.PARAM_ORDER_NUMBER, exampleDataElement.getOrderNumber());

      outputItemStructure.setAttributeValue(CContextInterface.PARAM_NAME, exampleDataElement.getName());

      outputItemStructure.setAttributeValue(CContextInterface.PARAM_PRICE, exampleDataElement.getPrice());

      outputItemStructure.setAttributeValue(CContextInterface.PARAM_CURRENCY, exampleDataElement.getCurrency());

      outputItemStructure.setAttributeValue(CContextInterface.PARAM_UNIT, exampleDataElement.getUnit());

     

      m_context.setResultState(RESULT_STATE_COMPLETED);

      m_context.processingComplete();

 

  } catch (GPInvocationException e) {

      String localizedMessage = m_TextAcc.getText("ERROR_SETTING_PARAMETERS");

      wdThis.wdGetWDCODisplaySelectItemsInterfaceController().wdFireEventTechnicalException(new GPTechnicalCallableObjectException(logger, localizedMessage, e));

  } catch (GPEngineException e) {

      String localizedMessage = m_TextAcc.getText("ERROR_SETTING_PARAMETERS");

      wdThis.wdGetWDCODisplaySelectItemsInterfaceController().wdFireEventTechnicalException(new GPTechnicalCallableObjectException (logger, localizedMessage, e));

   }

    //@@end

  }

Interface Controller

Properties

The WDCODisplaySelectItems component controller is required.

Interface Controller: Properties

This graphic is explained in the accompanying text

Methods

The available methods in the interface controller are inherited from the implemented interface IGPWebDynproCO (com.sap.caf.eu.gp.co.webdynpro):

     execute()

     getDescription()

Interface Controller: Methods

This graphic is explained in the accompanying text

Events

The component defines a TechnicalException event, which is inherited from the implemented interface. The event may occur when executing the component controller’s methods addItem(), createDescription() and mapInputToOutputParameters(); therefore, in the catch clause of these methods wdFireEventTechnicalException() is called.

With this exception handling mechanism, exceptions that occur in the Web Dynpro component are exposed to the GP framework for further processing.

 Interface Controller: Events

This graphic is explained in the accompanying text

Implementation

The implementation of the interface controller includes the following main aspects:

     Implementing method getDescription()

This method calls the createDescription() method of the component controller (see section Component Controller).

Method getDescription()

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

  {

    //@@begin getDescription()

    return wdThis.wdGetWDCODisplaySelectItemsController().createDescription(locale);

    //@@end

  }

     Implementing method execute()

This method invokes the execute() method of the component controller (see section Component Controller).

Method execute()

public void execute( com.sap.caf.eu.gp.context.api.IGPExecutionContext executionContext )

  {

    //@@begin execute()

   wdThis.wdGetWDCODisplaySelectItemsController().execute(executionContext);

    //@@end

  }

User Interface

The user interface of the component is implemented in view VDisplaySelectItems. The view is embedded in WebDynproCO that has been created when adding the implemented interface.

Properties

The component controllers of the following components are required for the implementation of the user interface part:

     CContext

     WDCODisplaySelectItems

View VDisplaySelectItems: Properties

This graphic is explained in the accompanying text

Context

In the context of the view, a structure ElementData is created with the same value attributes as the structure in the component controller (see section Component Controller). In addition, the structure and the attributes are mapped to the ones available in the component controller’s context (the data in the component controller’s context is retrieved from component CContext).

View VDisplaySelectItems: Context

This graphic is explained in the accompanying text

Actions

An action OrderItem is defined for the view. The action usage is discussed in the Layout section below. The implementation of the event handlers is shown in the Implementation section.

View VDisplaySelectItems: Actions

This graphic is explained in the accompanying text

Layout

The layout of the view includes the following UI elements:

     Header – contains the page heading 

     TextView – contains some explanatory text about the data that is displayed on the page

     Table – the available office materials with their attributes are displayed in a table. To populate the table with the data from the CContext component, you set the value of the dataSource table property to the ExampleData structure in the view’s context.

View VDisplaySelectItems: Layout (Table Properties)

This graphic is explained in the accompanying text

 

In addition, a column is defined for each item attribute that should be displayed, and the relevant value attribute from the view context is referenced in the text property of the column’s TextView.

View VDisplaySelectItems: Layout (Column Properties)

This graphic is explained in the accompanying text

     Button – the OrderItem action is linked to the button, so that its event handler is invoked when the button is chosen.

View VDisplaySelectItems: Layout (Button)

This graphic is explained in the accompanying text

Implementation

In the Implementation tabstrip the event handler for the OrderItem action must be implemented. The required behavior is to add the selected item to the collection of ordered items (output structures); therefore, the component controller’s addItem() method is called.

Method onActionOrderItem()

public void onActionOrderItem(com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent)

  {

    //@@begin onActionOrderItem(ServerEvent)

   wdThis.wdGetWDCODisplaySelectItemsController().addItem();

    //@@end

  }

Integration

For more information about the component’s usage in the process, see Display List and Select.

End of Content Area