Essential ATG Dynamo Training - Got atg Certified Relationship Management Developer?
This is not an official ATG site: ATG, Dynamo, Scenario Server and Personalization Server are trademarks or registered trademarks of Art Technology Group
Articles Exercises Resources Links Search

Custom Scenario Action Example

This example uses the event class from the custom event example

Overview

This example creates and configures a custom scenario event and action pair.

This example allows logged in users to participate in an Easter egg hunt around the site. For more reality, even by viewing the HTML source it would not be possible to tell which click might win, this is because the winning key value on the custom event is obscure.

The complete module is included here. Extract this file in ATG\Dynamo5.1 to and startDynamo with -m Training.CustomAction to see it at work. This module requires Dynamo Scenario Server and the Training.ClickTracker module to be installed.

The logged in user sees a grid of images, each hyper linked back to the same page. Only one of these links triggers the Easter- egg, but which one?!

The solution: The scenario listens for the custom Clicks event with a secret key (X76aads) and the fires the custom Found Easter Egg action before redirecting the user to a congratulations page.

Notice the custom icon for the action, that is specified in the scenarioManager.xml file and the gif file lives in the modules classpath.

EasterEggAction.java

package atg.customaction;

import atg.scenario.*;
import atg.scenario.action.*;
import atg.repository.*;
import atg.servlet.*;
import java.util.Map;

public class EasterEggAction extends ActionImpl
{

  public EasterEggAction()
  {
    System.out.println("EasterEggAction()");
  }
  public final String PAGE_URL = "PageURL";

  public void initialize(Map p) throws ScenarioException
  {
    this.storeRequiredParameter(p, PAGE_URL, String.class);
    System.out.println("initialize() : " + PAGE_URL + " in map = " + p.get(PAGE_URL));
  }

  /**
   * Executed when the member finds the easter egg
   */
  protected void executeAction(ScenarioExecutionContext cx) throws ScenarioException
  {
    try
    {
      DynamoHttpServletRequest req = cx.getRequest();
      RepositoryItem profile = cx.getProfile();
      String login = (String)profile.getPropertyValue("login");
      String page = (String)this.getParameterValue(PAGE_URL,cx);

      // Do whatever we want really...
      req.logInfo("Easter Egg Found on page " + page + " by " + login);
    }
    catch(Exception e)
    {
      System.out.println("EasterEggAction exception : " + e.getMessage());
    }
  }
}

scenarioManager.xml

We need to tell the Scenario Manager about our new action, that we do in /atg/scenario/scenarioManager.xml

<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE scenario-manager-configuration PUBLIC 
       "-//Art Technology Group, Inc.//DTD Scenario Manager//EN"
        'http://www.atg.com/dtds/scenariomanager/scenariomanager_1.0.dtd'>
<scenario-manager-configuration>
  <global-server></global-server>
  <action-registry>
    <action>
      <action-name>
        Found Easter Egg
      </action-name>
      <action-class>
        atg.customaction.EasterEggAction
      </action-class>
      <icon-resource>
        /atg/CustomAction/images/action-egg.gif
      </icon-resource>
      <description>
        Records the finding of the easter egg
      </description>
      <action-execution-policy>
        individual
      </action-execution-policy>
      <action-error-response>
        continue
      </action-error-response>
      <action-parameter>
        <action-parameter-name>
          PageURL
        </action-parameter-name>
        <required>
          true
        </required>
        <description>
          The page the egg was found on
        </description>
      </action-parameter>
    </action>
  </action-registry>
</scenario-manager-configuration>


Technical Training Advertise your Training Programs for Free! Los Angeles Web Design Shopping Cart Software  Form a Corporation