Tutorials > Program model > Add a finder to an existing entity bean

< Previous | Next >


Extend the Orders data bean

This section explains how to Extend the Orders data bean.

Your store JSP page should not call an access bean directly. To access the new finder method, we will extend the existing OrderListDataBean to contain a new method called getOrdersByTimePlaced. The getOrdersByTimePlaced method calls the findOrdersByTimePlaced method in the OrderAccessBean. Your store JSP page will then use JSTL to call the getOrdersByTimePlaced method.

To extend the Orders data bean:


Procedure

  1. In the Enterprise Explorer view, navigate to WebSphereCommerceServerExtensionsLogic > src.

  2. Create the com.ibm.commerce.sample.databeans package if it does not already exist:

    1. Right-click on the src folder and select New > package.

    2. In the New Java Package window, in the Name field, enter com.ibm.commerce.sample.databeans.

    3. Click Finish.

  3. Right-click on the com.ibm.commerce.sample.databeans package and select New > Class.

  4. In the New Java Class window enter the following values:

    1. In the Name field, enter ExtendedOrderListDataBean.

    2. In the Superclass field, enter com.ibm.commerce.order.beans.OrderListDataBean.

    3. Select Constructors from superclass.

    4. Leave all other default values and click Finish.

  5. Add the following method to the new ExtendedOrderListDataBean class:

    /*
    * This method returns a Vector of OrderDataBeans sorted by the
    TIMEPLACED database column.
    */
    public Vector getOrdersByTimePlaced() {
    final String strMethod = "getOrdersByTimePlaced";
    
    /*
    * This Enumeration will hold the results of 
    *
    <code>findOrdersByTimePlaced()</code>.
    */
    Enumeration enums;
    
    /*
    * This OrderAccessBean will hold the OrderAccessBeans 
    * in the Enumeration returned by
    <code>findOrdersByTimePlaced()</code>.
    */
    OrderAccessBean oab = new OrderAccessBean();
    
    /*This Vector will hold the result of the finder. */
    Vector resultVector = new Vector();
    
    try {
        /* Get the results of
    <code>findOrdersByTimePlaced()</code>. */
        enums = oab.findOrdersByTimePlaced(getUserId());
    
        /* Loop through all the results and add them to the
    <code>resultVector</code>. */
        while (enums.hasMoreElements()) {
            OrderDataBean odb=new
    OrderDataBean((OrderAccessBean)enums.nextElement(),this.getCommandContext());
            resultVector.add(odb); 
        } 
        return resultVector;
    
    } 
    catch (Exception e) {
        ECMessageLog.out(ECMessage._ERR_GENERIC, getClass().getName(),strMethod, new Object[] { e.toString() }, e);
        return null;
    }
    }
    

  6. Select Source > Organize Imports to add the necessary import statements. When prompted, select java.util.Enumeration.

  7. Save the changes.

  8. Right-click on the WebSphereCommerceServerExtensionsLogic project and select Build Project.

< Previous | Next >


+

Search Tips   |   Advanced Search