Modifying a controller command

In this lesson, you enable the controller command logic and response view the command invokes. The controller command calls the view, passing it to an argument. The view loads the response jsp page to display in your Madisons starter store.

About this task

The controller command that you use in this tutorial, MyContactUsCmd, calls the view, passing it an argument, which the view receives from the HTML form that you will implement later. The view, MyContactUsAckView, loads the MyContactUsAckDisplay.jsp page, displaying an acknowledgement text in the store page that includes the argument. You enable the response view by registering the view in the struts-config-ext.xml file and loading an access control policy to access the view.

Procedure

  1. Determine the STOREENT_ID for you store:
    1. In a web browser, enter the following URL:
      http://localhost/webapp/wcs/admin/servlet/db.jsp
    2. In the SQL input, enter the following SQL statement:
      select STOREENT_ID from STOREENT where IDENTIFIER = 'Madisons_name'; 
      Where Madisons_name is the name of your Madisons starter store. This value will be referred to as Madisons_storeID throughout this tutorial.
    1. Record the STOREENT_ID for your store.
  2. Register the MyContactUsAckView view for your controller command:
    1. In the Enterprise Explorer view, expand Stores/WebContent/WEB-INF
    2. Right-click the struts-config-ext.xml file and select Open With > Struts Configuration File Editor
    3. Click the Action Mappings tab.
    4. In the Action Mappings section, click Add.
    5. Delete the default path value /action#, and enter the path value: /MyContactUsAckView
    6. In the Action Mapping attributes section, for the Type field, enter com.ibm.commerce.struts.BaseAction
    7. Click the Global Forwards tab.
    8. In the Global Forwards section, click Add.
    9. Delete the default name success and enter MyContactUsAckView/Madisons_storeID, where Madisons_storeID is your store unique identifier. If your store unique identifier is 10001, enter MyContactUsAckView/10001.
    10. In the Forward Attributes section, for the Path field, enter /StoreInfoArea/MyContactUsAckDisplay.jsp
    11. In the Forward Mapping Extensions section, for the Class Name field, enter com.ibm.commerce.struts.ECActionForward
    12. Save the file and keep the Struts Configuration File Editor open.
  3. Load the access control policies for the MyContactUsAckView view. The command-level access control policy specifies that all users are allowed to execute the command. This type of access control policy is acceptable for the development environment, but it may not be suitable under other circumstances. The access control policy is defined by the MyContactUsAckViewACPolicy.xml file, which you placed in the following directory during the preparing your workspace lesson: WCDE_installdir/xml/policies/xml
    1. In WebSphere Commerce Developer, stop the WebSphere Commerce Test Server.
    2. In a command prompt, navigate to the following directory: WCDE_installdir\bin
    3. Run the acpload command to load the access control policies:
      • For IBM i OS operating systemDB2OracleRun the acpload command with the following form:
        acpload db_user db_password inputXMLFile schema_name
        
        Where
        db_user
        The name of the database user.
        db_password
        The password for your database user.
        inputXMLFile
        The XML file that contains the access control policy specification. In this case, specify MyContactUsAckViewACPolicy.xml.
        schema_name

        DB2The name of the database user who created the database and owns the schema, in uppercase.

        For IBM i OS operating systemDo not specify this parameter. This parameter is not applicable.

        OracleThe name of the user who owns the tables.

        For example,
        acpload dbuser dbuserpwd MyContactUsAckViewACPolicy.xml DBUSER
      • Apache DerbyRun the acpload command with the access control policy XML file as the only parameter:
        acpload MyContactUsAckViewACPolicy.xml
    4. Navigate to the WCDE_installdir/logs directory. Inspect the acpload.log and messages.txt files to ensure that the access control policy loaded successfully. The messages.txt file may not exist if the load completed successfully. Check that the following policy files were created successfully in the WCDE_installdir/xml/policies/xml directory: MyContactUsAckViewACPolicy_idres.xml and MyContactUsAckViewACPolicy_xmltrans.xml. These two files are created as part of a successful idresgen utility process. If any other error files are generated in this directory, then an error occurred during the loading process.
  4. Enable the controller command, MyContactUsCmd by registering the command with the command registration framework and loading an access control policy for the command. To register the controller command, register the interface in the struts-config-ext.xml file and the association between the interface and its implementation class in the CMDREG table.
    Tip: In the following steps, the insert statement into the CMDREG table is not necessary. By default, the interface uses the default implementation. Therefore, this association between the interface and implementation class does not need to be specified in the command registry. It is included here for completeness and good programming practice.
    1. Start the WebSphere Commerce Test Server.
    2. Register MyContactUsCmd in the CMDREG table:
      1. In a web browser, enter the following URL: http://localhost/webapp/wcs/admin/servlet/db.jsp
      2. Enter the following SQL statement:
        insert into CMDREG (STOREENT_ID, INTERFACENAME, DESCRIPTION, CLASSNAME, TARGET) 
        values ( Madisons_storeID,'com.ibm.commerce.sample.commands.MyContactUsCmd', 
        'This is a new controller command for the Struts tutorial.', 
        'com.ibm.commerce.sample.commands.MyContactUsCmdImpl','Local'); 
        where Madisons_storeID is your store's unique identifier, which you determined in an earlier section.
      3. Click Submit Query to run the SQL statement.
    3. Register the interface in the struts-config-ext.xml file:
      1. The file struts-config-ext.xml should still be open for editing in the Struts Configuration File editor.
      2. In the Action Mappings tab, in the Action Mappings section, click Add. Delete the default path value /action# and enter /MyContactUsCmd.
      3. In the Action Mapping attributes section, for the Type field, enter com.ibm.commerce.struts.BaseAction.
      4. In the Action Mapping attributes section, for the Parameter field, enter com.ibm.commerce.sample.commands.MyContactUsCmd. The parameter field contains the interface name of the business logic to execute.
      5. Save the file and leave the Struts Configuration File Editor open. You will edit the file again later in this tutorial.
    4. Update the Struts Configuration registry component:
      1. Open the Administration Console and select Site on the Administration Console Site/Store Selection page.
      2. From the Configuration menu, click Registry. A list of registry components for the site displays.
      3. Select the check box for the Struts Configuration registry component and click Update. The Registry window reloads listing the status for the selected components as "Updating."
      4. Click Refresh to reload the Registry window. When the update is complete, the status column reads "Updated."
  5. Load the access control policies for the command. The access control policy is defined by the MyContactUsCmdACPolicy.xml file, which you placed in the following directory during the preparing your workspace lesson: WCDE_installdir/xml/policies/xml
    1. In WebSphere Commerce Developer stop the WebSphere Commerce Test Server.
    2. In a command prompt, navigate to the following directory: WCDE_installdir\bin
    3. Run the acpload command to load the access control policies:
      • For IBM i OS operating systemDB2OracleRun the acpload command with the following form:
        acpload db_user db_password inputXMLFile schema_name
        
        Where
        db_user
        The name of the database user.
        db_password
        The password for your database user.
        inputXMLFile
        The XML file that contains the access control policy specification. In this case, specify MyContactUsCmdACPolicy.xml.
        schema_name
        DB2The name of the database user who created the database and owns the schema, in uppercase.
        For IBM i OS operating systemDo not specify this parameter. This parameter is not applicable.
        OracleThe name of the user who owns the tables.
        For example,
        acpload dbuser dbuserpwd MyContactUsCmdACPolicy.xml DBUSER
      • Apache DerbyRun the acpload command with the access control policy XML file as the only parameter:
        acpload MyContactUsCmdACPolicy.xml
    4. Navigate to the WCDE_installdir/logs directory. Inspect the acpload.log and messages.txt files to ensure that the access control policy loaded successfully. The messages.txt file may not exist if the load completed successfully. Check that the following policy files were created successfully in the WCDE_installdir/xml/policies/xml directory: MyContactUsCmdACPolicy_idres.xml and MyContactUsCmdACPolicy_xmltrans.xml. These two files are created as part of a successful idresgen utility process. If any other error files are generated in this directory, then an error occurred during the loading process.