Entering content frame

Procedure documentation Adding a Supply Function Locate the document in its SAP Library structure

Our purpose here is to always adapt the Order entries in the (lower) detail table to match the entries for the currently selected Customer in the master table.

With respect to the context structure declared in the view controller, this means that the instantiated singleton value node Order is to be filled with a new list of Order-type node elements whenever the Customer selected in the upper table changes – that is, when the lead selection in the value node Customer changes. All you need to specify this list is the identifier of the currently-selected node element in the top-level node. ln addition, a reference to the value node Order must be known. The list of Order node elements is to be bound to this node.

This graphic is explained in the accompanying text

This graphic illustrates exactly this relationship. A supply function supplyOrdersForCustomer(Node node, NodeElement parentElement), for the inner value node Order, is called from the Web Dynpro runtime environment in the following cases:

·        The node elements contained in the node are not available, but are to be displayed. In our example, that is the case when the application is launched, when the Detail table is to be filled with the Order records for the first customer.

·        The lead selection of the top-level node changes. In the above example, this situation occurs when the user chooses a different Customer row in the master table. The Order list in the Detail table is then invalid and the application must specify it again by calling the supply function.

·        The inner value node, for which the supply function was declared, is invalidated by the application developer calling the method invalidate(). This means that the list of node elements associated with the value nodes is deleted. The supply function is then called, if these lists are accessed again at runtime. Invalidating a node automatically implies invalidation of all the subnodes contained in it.

In our example, we only need to communicate the selection of a new Customer row in the upper table by declaring an action event called CustomerSelected and by binding the Customer table to this action event of the Web Dynpro environment. The associated event handler, onActionCustomerSelected(), does not need to be implemented. The supply function is called implicitly through the Web Dynpro runtime environment, which reacts when the lead selection changes.

Procedure

To make the Master/Detail Viewer available:

Defining an event and binding it to the table

...

       1.      On the Actions tab of the Work view, declare an action and name it CustomerSelected.

       2.      On the Layout tab, bind the Event – onLeadSelect property of the UI element This graphic is explained in the accompanying text CustomerTable[Table] to the CustomerSelected action in the selection list on the right of the tab.

Declaring the supply function for an inner value node

       3.      In the Work view, choose the Context tab.

       4.      Select the inner context value node Order.

       5.      Assign the new supply function, supplyOrdersForCustomer, to the supplyFunction property. In the right-hand column, choose This graphic is explained in the accompanying text. In the dialog box that appears, enter the name of the supply function.

This graphic is explained in the accompanying text

Implementing the supply function

       6.      Choose the Implementation tab to implement the view controller called Work.java.

       7.      After the supply function supplyOrdersForCustomer the controller implementation is extended to include this method. Insert the following source code in the user coding area:

Supply function supplyOrdersForCustomer() in the Work view controller

...

/**

 * Declared supply function for IPrivateWork.IOrderNode.

 * This method is called when the node is invalid and the collection is

 * requested. This may occur in any phase, even in the beginning to

 * initialize the node. The method is expected to fill the node

 * collection using IWDNode.bind(Collection) or IWDNode.addElement(IWDNodeElement).

 *

 * @param node The node that is to be filled

 * @param parentElement The element that this node is child of. May be

 *        <code>null</code> if there is none.

 * @see com.sap.tc.webdynpro.progmodel.api.IWDNode#bind(Collection)

 * @see com.sap.tc.webdynpro.progmodel.api.IWDNode#bind(IWDNodeElement)

 */

public void supplyOrdersForCustomer(IPrivateWork.IOrderNode node,

                                    IPrivateWork.ICustomerElement parentElement)

{

  //@@begin supplyOrdersForCustomer(IWDNode,IWDNodeElement)

  SomeBOL.Order order;

  IPrivateWork.IOrderElement newOrderNodeElement;       

  // get list of Orders for given customer from some BOL

  Collection orders = someBOL.getOrdersForCustomer(parentElement.getName());

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

    order = (SomeBOL.Order)iter.next();

    // create new instance of a node element of type Order

    newOrderNodeElement = wdContext.createOrderElement();     

    // set context value attributes contained in context value node of type Order

    newOrderNodeElement.setCurrency(order.getCurrency());

    newOrderNodeElement.setDate(order.getDate());

    newOrderNodeElement.setPrice(order.getPrice());

    newOrderNodeElement.setProduct(order.getProduct());

    // Add new node element of type Order to node of type IPrivateWork.IOrderNode.

    // This means: add node element newOrderNodeElement to collection of

    // node elements hold by singleton context value node node (Order)

    node.addElement(newOrderNodeElement);

  }  

  //@@end

} 

...

 

Result

After you include the supply function supplyOrdersForCustomer, the Master/Detail application behaves as desired in the Web browser. Each time the user selects a different row in the upper table, the details table is filled again with the associated order records. As an application developer, you simply need to implement a suitable supply function for the inner value node Order and bind the LeadSelect event of the customer table to an action, to trigger communication with the runtime environment. Each row entry in the Order table is transported again using the mechanism of data binding between table UI elements and the controller context of a view.

  

  

 

Leaving content frame