Tutorials > Sales Center > Add an editable column to the Order Items table by creating a new widget manager

< Previous | Next >


Create a new class and add code to get the fulfillment list

In this step of the tutorial, you create a new class and add code to get the fulfillment list.

In this step, you create a new package and class to extend the base ShowStore class based on the information you gathered in the last step.

  1. Open WebSphere Commerce Developer.

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

  3. Right-click the src project and select New > Package.

  4. In the Name field, type com.mynewextensions.fulfillmentcenter and click Finish.

  5. Right-click the com.mynewextensions.fulfillmentcenter package and select New > Class.

  6. In the Name field, enter ExtendedShowStore.

  7. Next to the Superclass field, click Browse.

  8. In the Choose a type field, enter ShowStore and click OK.

  9. Click Finish.

  10. Copy and paste the following code within the brackets (based on the ShowStore API) :

    For this example, we assume that there are no access control issues. The access bean is used to retrieve the data from the database in this tutorial. You can create a databean if handle access control issues.

            /**     Variable names declarations
             */
            
            private static final ECMessage USER_ERR_MSG = new
    ECMessage("ERROR: There are no Fulfillment Centers!"); //Custom
    error message
            private static final String CLASSNAME =
    ExtendedShowStore.CLASS_NAME;
            private static final String METHODNAME =
    "createStoreElement";
            private static final String EXAMPLE_NS = 
    "http://www.example.com/commerce/telesales"; //sample namespace
            private static final String EXAMPLE_NS_ATTR =  "xmlns:cu";
            private static final String TAG_FULFILLMENT_CENTERS_LIST =
    "cu:Fulfillment_Center_List"; //tags to be created in BOD
            private static final String TAG_FULFILLMENT_CENTER =
    "cu:Fulfillment_Center";
            private static final String TAG_FULFILLMENT_CENTER_ID =
    "cu:Id";
            private static final String TAG_FULFILLMENT_CENTER_DESC =
    "cu:Desc";
                    
    
            /**
             * setNameSpaceAttributesForRootDocumentElement sets the
    name space attributes for the given root document element.
             * In this method a custom namespace  and its attribute tag
    is create as identified as EXAMPLE_NS_ATTR and EXAMPLE_NS above. 
             * This is done so that later on you can use this custom
    namespace to differentiate the elements from the base code
    elements. 
             * @param aRootElement - org.w3c.dom.Element
             * @return org.w3c.dom.Element
             */
            
            protected org.w3c.dom.Element
    setNameSpaceAttributesForRootDocumentElement(org.w3c.dom.Element
    aRootElement){
                    
                    //Writes a trace entry writes in the trace file to
    record the entrance to a method for debugging purposes
                   
    ECTrace.entry(ECTraceIdentifiers.COMPONENT_MESSAGING, CLASSNAME,                                 METHODNAME);
                    
                    // Creates an element that calls its super to set
    the namespace attributes for the root document element in the BOD
                    Element snsafrde =
    super.setNameSpaceAttributesForRootDocumentElement(aRootElement);
                    
                    //Puts the namespace in the root element to be
    added at the very top of the xml BOD
                    snsafrde.setAttribute(EXAMPLE_NS_ATTR, EXAMPLE_NS);
                    
                    //Writes a trace entry in the trace file to record
    the exit to a method for debugging purposes
                   
    ECTrace.exit(ECTraceIdentifiers.COMPONENT_MESSAGING, CLASSNAME,                                 METHODNAME);
                    
                    //returns the customized element
                    return snsafrde;
            }
            
    
            /**
             * createStoreElement builds the Store element from the
    specified store search result data bean. 
             * In this method, custom code will be added to read
    information from the database and create nested element
             * tags within the Store element tag.
             * @param aParentElement - org.w3c.dom.Element
             * @param abnStoreSearchResult - StoreSearchResultBean
             * @return org.w3c.dom.Element
             * @throws ECException
             */
            
            public org.w3c.dom.Element createStoreElement(
                            org.w3c.dom.Element aParentElement,                         StoreSearchResultBean abnStoreSearchResult)
    throws ECException {
                    
                    //Writes a trace entry writes in the trace file to
    record the entrance to a method for debugging purposes
                   
    ECTrace.entry(ECTraceIdentifiers.COMPONENT_MESSAGING, CLASSNAME,                                 METHODNAME);
                    
                    // Creates an element that calls its super to build
    all the other attributes into the BOD message       
                    Element storeParent =
    super.createStoreElement(aParentElement,                                 abnStoreSearchResult);
                    
                    //Checks to see if a specific store has been
    selected
                    if (abnStoreSearchResult.getRetrieveDetailsFlag()
    == true) {
                            
                            //      Creates the Fulfillment_Center_List
    tag in the BOD
                            Element fulfillmentCentersListElement =
    createDocumentElementNS(EXAMPLE_NS,                                         storeParent, TAG_FULFILLMENT_CENTERS_LIST);
    
                            
                            
                            try {
                                    
                                    //Initializing a helper access bean
    to get information from the database
                                    FulfillmentJDBCHelperAccessBean fhb
    = new FulfillmentJDBCHelperAccessBean();
                                    
                                    //      Obtain the Store ID
                                    int StoreId =
    Integer.parseInt(abnStoreSearchResult
                                                   
    .getStoreBaseInfo().getStoreEntityId());
                                    
                                    // Searches for FFCs via the access
    bean 
                                    Vector vFFCs =
    fhb.findFfmcenterNameAndIdByStoreId(new Integer(
                                                    StoreId));
    
                                    // If the vector is non empty
                                    if (vFFCs != null) {
                                    
                                            // For storing Fullfilment
    center contents
                                            Vector aFFCelements = new
    Vector();
                                            
                                            //Enumerates the FFC
    elements
                                            Enumeration fulfillId =
    vFFCs.elements();
    
                                            // If fullfillId is has
    more than one element
                                            while
    (fulfillId.hasMoreElements()) {
                                                    
                                                    //Store the
    contents of each element
                                                    aFFCelements =
    (Vector) fulfillId.nextElement();
                                                    
                                                    //If fulfillment ID
    or Description is empty, move to the next element
                                                    if
    (aFFCelements.elementAt(1) == null
                                                                    ||
    aFFCelements.elementAt(0) == null) {
                                                            continue;
                                                    }
                                                    
                                                    //Separates and
    stores each content as a string object
                                                    String ffmId =
    aFFCelements.elementAt(1).toString();
                                                    String ffcDesc =
    aFFCelements.elementAt(0).toString();
    
                                                    
    
                                                    // Creates the
    Fulfillment_Center tag in the BOD
                                                    Element
    fulfillmentCenterElement = createDocumentElementNS(EXAMPLE_NS, fulfillmentCentersListElement, 
                                                                   
    TAG_FULFILLMENT_CENTER);
    
                                                    // Creates the Id
    tag in the BOD
                                                   
    createDocumentElementNS(EXAMPLE_NS, fulfillmentCenterElement,                                                                
    TAG_FULFILLMENT_CENTER_ID, ffmId);
    
                                                    //       Creates
    the Desc tag in the BOD
                                                   
    createDocumentElementNS(EXAMPLE_NS, fulfillmentCenterElement,                                                                
    TAG_FULFILLMENT_CENTER_DESC, ffcDesc);
                                            }
    
    
                                                                       
        
                                    } 
                                    else {
                                            //No Fulfillment centers
    exists.
                                            throw new
    ECApplicationException(USER_ERR_MSG,CLASSNAME, METHODNAME);
                                    }
                            //Appropriate Catch Statements
                            } catch (javax.naming.NamingException e) {
                                    throw new
    ECSystemException(ECMessage._ERR_NAMING_EXCEPTION, CLASSNAME,                                                 METHODNAME, ECMessageHelper.generateMsgParms(e
                                                                   
    .toString()), e);
    
                            } catch (FinderException e) {
                                    throw new
    ECSystemException(ECMessage._ERR_FINDER_EXCEPTION,                                                 CLASSNAME, METHODNAME, ECMessageHelper
                                                                   
    .generateMsgParms(e.toString()), e);
    
                            } catch (CreateException e) {
                                    throw new
    ECSystemException(ECMessage._ERR_CREATE_EXCEPTION,                                                 CLASSNAME, METHODNAME, ECMessageHelper
                                                                   
    .generateMsgParms(e.toString()), e);
    
                            } catch (RemoteException e) {
                                    throw new
    ECSystemException(ECMessage._ERR_REMOTE_EXCEPTION,                                                 CLASSNAME, METHODNAME, ECMessageHelper
                                                                   
    .generateMsgParms(e.toString()), e);
    
                            } catch (SQLException e) {
                                    throw new
    ECSystemException(ECMessage._ERR_SQL_EXCEPTION,                                                 CLASSNAME, METHODNAME, ECMessageHelper
                                                                   
    .generateMsgParms(e.toString()), e);
                            }
    
                    }
                    
                    //      Writes a trace entry in the trace file to
    record the exit to a method for debugging purposes
                   
    ECTrace.exit(ECTraceIdentifiers.COMPONENT_MESSAGING, CLASSNAME,                                 METHODNAME);
                    
                    // returns the customized element
                    return storeParent;
            }
    

  11. To resolve the import errors, click Source > Organize Imports. When prompted for the Element type, choose the standard class which is org.w3c.dom.Element; there are many classes for it. The variable name declarations at the top are to be used later when you add code to this class. Notice also that for debugging purposes, ECTrace can write the entry and exit points when these methods are called in a WebSphere Commerce trace log file.

< Previous | Next >


+

Search Tips   |   Advanced Search