Sustituir la vista llamada mediante un mandato de controlador

Para sustituir la vista llamada por un mandato de controlador, cree una nueva clase de implementación para el mandato de controlador. Por ejemplo, cree un nuevo ModifiedControllerCmdImpl que amplíe ExistingControllerCmdImpl e implemente la interfaz ExistingControllerCmd. Tenga en cuenta que esto solo es aplicable a la capa de aplicaciones web.

Por qué y cuándo se efectúa esta tarea

Dentro de la clase ModifiedControllerCmdImpl, sustituya el método performExecute. En el nuevo método performExecute, llame a super.performExecute para asegurarse de que tiene lugar todo el proceso de mandatos. Después de ejecutar toda la lógica de mandatos, puede utilizar las propiedades de respuesta para modificar la vista llamada. El fragmento de código siguiente muestra cómo modificar una vista de redirección:


// 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);
         }
   }    

El fragmento de código siguiente muestra cómo modificar una vista de reenvío:


// 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");  
         }
    }