Tutorials > Program model > Use Struts tags, action forms, and validation

< Previous | Next >


Enable back-end logic

In this step, we will enable the back-end logic, whose implementation you imported in the previous step.

The back-end logic consists of a controller command and a response view that it invokes. The controller command, MyContactUsCmd, calls the view, passing it an argument, which it will eventually get from the HTML form we will implement in a later step. The view, MyContactUsAckView, loads the MyContactUsAckDisplay.jsp page, displaying an acknowledgement text that includes the argument.

Enable the response view

You will first enable the response view, MyContactUsAckView, by registering it in the struts-config-ext.xml file and loading an access control policy for it.

Determine the unique identifier of the store

In order to register the view, determine the unique identifier for your store.


Procedure

  1. Start the test environment.

  2. Open a browser and type the following URL: http://localhost/webapp/wcs/admin/servlet/db.jsp.

  3. In the input box, enter the following SQL statement: select STOREENT_ID from STOREENT where IDENTIFIER = ' ConsumerDirect_name'; where ConsumerDirect_name is the name of the store. This value will be referred to as ConsumerDirect_storeID throughout this tutorial.

  4. Register MyContactUsAckView

    1. In the Enterprise Explorer view, expand Stores > Struts > <default module>.

    2. Right-click the struts-config-ext.xml file and select Open With > Struts Configuration File Editor.

    3. In the Action Mappings tab:

      1. In the Actions Mappings section, click Add. Delete the default path value <no path> and enter /MyContactUsAckView.

      2. In the Action Mapping attributes section, in the Type field, enter com.ibm.commerce.struts.BaseAction.

    4. Enter values for the new view:

      1. In the Global Forwards tab, click Add. Delete the default name <no name> and enter MyContactUsAckView/ ConsumerDirect_storeID, where ConsumerDirect_storeID is the store's unique identifier, which you determined in the preceding section. For example, if the store's unique identifier is 10001, you would enter MyContactUsAckView/10001.

      2. In the Forward Attributes section, in the Path field, enter /StoreInfoArea/MyContactUsAckDisplay.jsp.

      3. In the Forward Mapping Extensions section, in the Class Name field, enter com.ibm.commerce.struts.ECActionForward.

    5. Save the file and leave it open. You will edit the file again later in this tutorial.

  5. Load access control policies for MyContactUsAckView

    You must specify access control policies for the new view. In this case, the command-level access control policy specifies that all users are allowed to execute the command. Note that this type of access control policy is acceptable for the development environment, but it might not be suitable for other circumstances.

    The access control policy is defined by the MyContactUsAckViewACPolicy.xml file, which you placed into the following directory, as part of the preparatory steps: WC_EAR\xml\policies\xml.

    1. Stop the test environment.

    2. At a command prompt, navigate to the following directory: WCDE_INSTALL/\bin

    3. Run the acpload command, which has the following form:

      acpload 
      db_host_name db_name 
      db_user 
      db_password 
      inputXMLFile 
      schema_name
      

      Where:

      db_host_name

      Do not specify this parameter. This parameter is not applicable.

      The hostname of the machine on which the development database runs.

      db_name

      The name of the development database.

      Do not specify this parameter. This parameter is not applicable.

      db_user

      The name of the database user.

      db_password

      The password for the database user.

      inputXMLFile

      The XML file containing the access control policy specification. In this case, specify MyContactUsAckViewACPolicy.xml.

      schema_name

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

      Do not specify this parameter. This parameter is not applicable.

      The name of the user who owns the tables.

      For example,

      acpload Demo_Dev dbuser dbuserpwd MyContactUsAckViewACPolicy.xml
      DBUSER
      

    4. Run the acpload command with the access control policy XML file as the only parameter:

      acpload 
      MyContactUsAck
      ViewACPolicy.xml
      

    5. Navigate to the WCDE_INSTALL/\logs directory. Inspect the acpload.log and messages.txt files to ensure that the access control policy loaded successfully. The messages.txt file might not exist if the load completed successfully. Also, check if the following policy files were created successfully in the WC_EAR\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, this indicates that there was a problem.

  6. Enable the controller command

    You will now enable the controller command, MyContactUsCmd, by registering it with the command registration framework and loading an access control policy for it.

    To register the MyContactUsCmd controller command, you 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 absolutely necessary. By default, the interface uses the default implementation, and as such, this association between the interface and implementation class does not really need to be specified in the command registry. It is included here for the purpose of completeness and good programming practice.

    To register MyContactUsCmd:

    1. Start the test environment.

    2. Register MyContactUsCmd in the CMDREG table:

      1. Open a browser and type 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 ( ConsumerDirect_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 ConsumerDirect_storeID is the 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 <no path> and enter /MyContactUsCmd.

      3. In the Action Mapping attributes section, in the Type field, enter com.ibm.commerce.struts.BaseAction.

      4. In the Action Mapping attributes section, in 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 it open. You will edit the file again later in this tutorial.

    4. Update the registry component named Struts Configuration:

      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 updating is complete, the status column reads "Updated."

  7. Load access control policies for the command

    You must specify access control policies for the new command. In this case, the command-level access control policy specifies that all users are allowed to execute the command. Note that this type of access control policy is acceptable for the development environment, but it might not be suitable for other circumstances.

    The access control policy is defined by the MyContactUsCmdACPolicy.xml file, which you placed into the following directory, as part of the tutorial's prerequisite steps: WC_EAR\xml\policies\xml.

    To load the new policy:

    1. Stop the test environment.

    2. At a command prompt, navigate to the following directory: WCDE_INSTALL/\bin

    3. Run the acpload command, which has the following form:

      acpload db_host_name db_name db_user db_password inputXMLFile schema_name
      

      Where:

      db_host_name

      Do not specify this parameter. This parameter is not applicable.

      The hostname of the machine on which the development database runs.

      db_name

      The name of the development database.

      Do not specify this parameter. This parameter is not applicable.

      db_user

      The name of the database user.

      db_password

      The password for the database user.

      inputXMLFile

      The XML file containing the access control policy specification. In this case, specify MyContactUsCmdACPolicy.xml.

      schema_name

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

      Do not specify this parameter. This parameter is not applicable.

      The name of the user who owns the tables.

      For example,

      acpload Demo_Dev dbuser dbuserpwd MyContactUsCmdACPolicy.xml DBUSER
      

    4. Run the acpload command...

      acpload 
      MyContactUsCmdACPolicy.xml 
      

    5. Navigate to the WCDE_INSTALL/\logs directory. Inspect the acpload.log and messages.txt files to ensure that the access control policy loaded successfully. The messages.txt file might not exist if the load completed successfully. Also, check if the following policy files were created successfully in the WC_EAR\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, this indicates that there was a problem.

  8. Test the back-end logic

    Now that the response view and the controller command have been enabled, you can test the entire back-end logic piece...

    1. Start the test environment.

    2. Navigate to the Stores > WebContentConsumerDirect_name directory.

    3. Select the index.jsp file, then click Run As > Run on Server.

    4. A message might display asking you to select a server. Select Choose an existing server and click Finish.

    5. On the store locale selection page that is displayed in the Web browser, click United States English.

    6. Examine the URL contained in the Address field of the Web browser. It should look similar to the following:

      http://localhost/webapp/wcs/stores/servlet/TopCategoriesDisplay?langId=-1&storeId=10001&catalogId=10001
      

    7. Edit the URL contained in the Address field of the Web browser as follows:

      http://localhost/webapp/wcs/stores/servlet/MyContactUsCmd?langId=-1&storeId=10001&catalogId=10001&name=customer 
      

      The values of the langId, storeId, and catalogId URL parameters you see in the Address field of the Web browser might be different from those in this example. Keep them unchanged. Only changed the highlighted portions or the URL.

    8. Press Enter or click Go.

    9. You should see the Contact Us Acknowledgement page display addressing you as customer.

< Previous | Next >


+

Search Tips   |   Advanced Search