Replacing the view called by a controller command

To replace the view that is called by a controller command, create a new implementation class for the controller command. For example, create a new ModifiedControllerCmdImpl that extends ExistingControllerCmdImpl and implements the ExistingControllerCmd interface. Note that this is only applicable to the Web application layer.

About this task

Within the ModifiedControllerCmdImpl class, override the performExecute method. In the new performExecute method, call super.performExecute to ensure that all command processing occurs. After the command logic is executed, you can use the response properties to override the view called. The following code snippet displays how to override a redirect view:


// Import the packages containing TypedProperty and ECConstants.
import com.ibm.commerce.datatype.*;
import com.ibm.commerce.server.*;

public class ModifiedControllerCmdImplImpl extends ExistingControllerCmdImpl 
   implements ExistingControllerCmd 
   {
      public void performExecute () 
         throws com.ibm.commerce.exception.ECException 
         {
            // Execute the original command logic.
            super.performExecute();

            // Use the response properties returned from the superclass (preceding call).
            // If the superclass has not returned any, then create a new response 
            // properties object.
            TypedProperty responseProperties = getResponseProperties();
            if (responseProperties == null) 
            {
                    responseProperties = new TypedProperty();
                    setResponseProperties(responseProperties);
            }

            // Replace the view name in the response properties.
            responseProperties.put(ECConstants.EC_VIEWTASKNAME, "MyView");

            ///////////////////////////////////////////////////// 
            //  The following line is optional. The Struts     //
            //  configuration files can specify the redirect   //
            //  URL.                                           //
            /////////////////////////////////////////////////////
            responseProperties.put(ECConstants.EC_REDIRECTURL, MyURL);
         }
   }    

The following code snippet displays how to override a forward view:


// Import the packages containing TypedProperty and ECConstants.
import com.ibm.commerce.datatype.*;
import com.ibm.commerce.server.*;

public class ModifiedControllerCmdImplImpl extends ExistingControllerCmdImpl 
   implements ExistingControllerCmd 
   {
      public void performExecute () 
         throws com.ibm.commerce.exception.ECException 
         {
            // Execute the original command logic.
            super.performExecute();

            // Use the response properties returned from the superclass (preceding call).
            // If the superclass has not returned any, then create a new response 
            // properties object.
            TypedProperty responseProperties = getResponseProperties();
            if (responseProperties == null) 
            {
                    responseProperties = new TypedProperty();
                    setResponseProperties(responseProperties);
            }

            // Replace the view name in the response properties.
            responseProperties.put(ECConstants.EC_VIEWTASKNAME, "MyView");

            ///////////////////////////////////////////////////// 
            //  The following line is optional. The Struts     //
            //  configuration files can specify the JSP page.  //
            /////////////////////////////////////////////////////
            responseProperties.put(ECConstants.EC_DOCPATHNAME, "MyJSP.jsp");  
         }
    }