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
- Determine the STOREENT_ID for you store:
- In a web browser, enter the following URL:
http://localhost/webapp/wcs/admin/servlet/db.jsp
- In the SQL input, enter the following SQL statement:
Where Madisons_name is the name of your Madisons starter store. This value will be referred to as Madisons_storeID throughout this tutorial.select STOREENT_ID from STOREENT where IDENTIFIER = 'Madisons_name';
- Record the STOREENT_ID for your store.
- In a web browser, enter the following URL:
- Register the
MyContactUsAckView
view for your controller command:- In the Enterprise Explorer view, expand Stores/WebContent/WEB-INF
- Right-click the struts-config-ext.xml file and select Open With > Struts Configuration File Editor
- Click the Action Mappings tab.
- In the Action Mappings section, click Add.
- Delete the default path value /action#, and enter the path value: /MyContactUsAckView
- In the Action Mapping attributes section, for the Type field, enter com.ibm.commerce.struts.BaseAction
- Click the Global Forwards tab.
- In the Global Forwards section, click Add.
- 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, enterMyContactUsAckView/10001
. - In the Forward Attributes section, for the Path field, enter /StoreInfoArea/MyContactUsAckDisplay.jsp
- In the Forward Mapping Extensions section, for the Class Name field, enter com.ibm.commerce.struts.ECActionForward
- Save the file and keep the Struts Configuration File Editor open.
- 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- In WebSphere Commerce Developer, stop the WebSphere Commerce Test Server.
- In a command prompt, navigate to the following directory: WCDE_installdir\bin
- Run the acpload command to load the access control policies:
- Run 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
-
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 dbuser dbuserpwd MyContactUsAckViewACPolicy.xml DBUSER
- Run the acpload command with the access control
policy XML file as the only parameter:
acpload MyContactUsAckViewACPolicy.xml
- Run the acpload command
with the following form:
- 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.
- 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.
- Start the WebSphere Commerce Test Server.
- Register MyContactUsCmd in
the CMDREG table:
- In a web browser, enter the following URL:
http://localhost/webapp/wcs/admin/servlet/db.jsp
- Enter the following SQL statement:
where Madisons_storeID is your store's unique identifier, which you determined in an earlier section.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');
- Click Submit Query to run the SQL statement.
- In a web browser, enter the following URL:
- Register the interface in the struts-config-ext.xml file:
- The file struts-config-ext.xml should still be open for editing in the Struts Configuration File editor.
- In the Action Mappings tab, in the Action Mappings section, click Add. Delete the default path value /action# and enter /MyContactUsCmd.
- In the Action Mapping attributes section, for the Type field, enter com.ibm.commerce.struts.BaseAction.
- 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. - Save the file and leave the Struts Configuration File Editor open. You will edit the file again later in this tutorial.
- Update the Struts Configuration registry component:
- Open the Administration Console and select Site on the Administration Console Site/Store Selection page.
- From the Configuration menu, click Registry. A list of registry components for the site displays.
- 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."
- Click Refresh to reload the Registry window. When the update is complete, the status column reads "Updated."
- 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
- In WebSphere Commerce Developer stop the WebSphere Commerce Test Server.
- In a command prompt, navigate to the following directory: WCDE_installdir\bin
- Run the acpload command to load the access control policies:
- Run 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
- 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 dbuser dbuserpwd MyContactUsCmdACPolicy.xml DBUSER
- Run the acpload command with the access control
policy XML file as the only parameter:
acpload MyContactUsCmdACPolicy.xml
- Run the acpload command
with the following form:
- 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.