コンテンツエリア開始

Procedure documentation Initializing the Controller Context of a View Locate the document in its SAP Library structure

Initializing the declared controller context of the view is the crux of this example application, in a technical programming sense.

In this section, you will learn how to fill single value nodes with associated node elements at runtime using generated context interface methods, to display these using data binding in the two tables CustomerTable and OrderTable. The master table CustomerTable will then look like this in the Web browser:

This graphic is explained in the accompanying text

In the above graphic, the lead selection of the first node element of the value node Customers is indicated by the fact that the first row in the table is highlighted.

Procedure

This graphic is explained in the accompanying text

The graphic shows which context data structure must be available for filling the Customer table using data binding.

As you can see, several address data records (node element of type IAddressElement) must be instantiated at the same time, for you to be able to display them in all rows of the Customer table (and thus separately for each customer). This is why the value node Address is declared as a non-singleton node.

The value node Customers is filled step-by-step:

        Instantiating node elements: Repeated instantiation of a node element of the type ICustomersElement.

        Defining value attributes: Assigning values for the value attributes declared in the node element of the type ICustomersElement – in this case for the Name attribute.

        Inserting node elements: Inserting the node elements of the type ICustomersElement in the value node Customers. “Inserting” means adding the elements to the list of node elements that have been aggregated from the value node Customers.

A similar procedure is then carried out with each node element of the type IAddressElement. Each of these elements is inserted in the appropriated Address value node, which has been instantiated separately for each node element.

This graphic is explained in the accompanying text

Note that each individual node element of the type ICustomersElement has its own Address value node instance only because the value node Address was declared as a non-singleton node at design time. Otherwise, you would only be able to access directly the one instance of Address associated with the current lead selection of the Customer value node, in the controller context, by calling the method wdContext.nodeAddress().

...

...

       1.      Now implement the wdDoInit()method of the Work view controller. When doing so, make sure you add the import statements and the declare the instance variable someBOL.

 

Implementation of the wdDoInit()method in the Work view controller

...

//@@begin imports

import java.util.*;

import com.sap.tc.webdynpro.tutorials.masterdetail.bol.SomeBOL;

import com.sap.tc.webdynpro.tutorials.masterdetail.wdp.IPrivateWork;

//@@end

...

/** Hook method called to initialize controller. */

public void wdDoInit()

{

  //@@begin wdDoInit()

  SomeBOL.Customer customer;       

  SomeBOL.Address address;    

  IPrivateWork.ICustomersElement newCustomerNodeElement;

  IPrivateWork.IAddressElement newAddressNodeElement;

 

  someBOL.initialize();

  Collection customers = someBOL.getCustomers();

 

  // ======== Populate context ===================

  for (Iterator iter = customers.iterator(); iter.hasNext();){

    customer = (SomeBOL.Customer)iter.next();

    address = customer.getAddress();

    // Instantiate new value node element of type ICustomersElement

    // and define attributes

    newCustomerNodeElement = wdContext.createCustomersElement();

    newCustomerNodeElement.setName(customer.getName());

    // The creation of a new inner node element instance requires

    // the existence of a parent node element already bound to the

    // parent node. So call method bind() (or alternatively addElement()) before.

    wdContext.nodeCustomers().addElement(newCustomerNodeElement);

    // Instantiate new value node element of type IAddressElement

    // and define attributes.

    newAddressNodeElement = wdContext.createAddressElement();

    newAddressNodeElement.setCity(address.getCity());

    newAddressNodeElement.setCountry(address.getCountry());

    newAddressNodeElement.setHouseNo(address.getHouseNo());

    newAddressNodeElement.setPostalCode(address.getPostalCode());

    newAddressNodeElement.setStreet(address.getStreet());     

    // the dependent context value node Address can only be referenced here for

    // each context value node element of type ICustomersElement separately because

    // we defined it to be a non-singleton node. 

    newCustomerNodeElement.nodeAddress().bind(newAddressNodeElement);

  }        

  //@@end

}

...

/*

 * The following coding section can be used for any Java coding that has

 * not to be visible to other controllers/views or that contains constructs

 * currently not supported directly by Web Dynpro (such as inner classes or

 * member variables etc.). </p>

 *

 * Note: The content of this section is in no way managed/controlled

 * neither by the Web Dynpro Designtime nor the Web Dynpro Runtime.

 */

//@@begin others

public SomeBOL someBOL = new SomeBOL();

//@@end

...

This graphic is explained in the accompanying text

Note that, if you call the method bind(newCustomerNodeElement) instead of addElement(newCustomerNodeElement), only the last bound node element of the type Customer is contained in the list of node elements. That is, wdContext.nodeCustomers().bind(newCustomerNodeElement) overwrites the list of node elements of the type Customer.

Result

Once the Master/Detail Viewer has been generated again and deployed in the Web browser again, it looks like this:

This graphic is explained in the accompanying text

The (upper) Customer table is filled correctly by means of the data binding (already declared) between the UI elements associated with the table and the context elements. Conversely, the Order table remains empty. How can we display the order records, for the selected customer, in the Detail table (that is, the Orders for Customers table)?

This graphic is explained in the accompanying text   To answer this question, refer to the section Implementation of a Supply Function!

  

  

 

コンテンツエリア終了