Conga Product Documentation

Welcome to the new doc site. Some of your old bookmarks will no longer work. Please use the search bar to find your desired topic.

Show Page Sections

External Action

The following example shows how to create a simple external action, which can be used by the Configurator UI application. The external action purpose is to provide a functionality that is not implemented by the predefined actions of the application.

The external action implemented in the following example changes the view by adding a message to the information flyer that will be shown on Ajax update.

Setting the development environment up



The following libraries are needed:

  • Internal – supplied by PROS:
    • externalComponentsFramework.jar
      • ConfiguratorUI service layer
    • ConfiguratorEngine.jar
      • Configurator Engine layer
    • business.jar
      • configuration engine public business objects
    • framework.jar
      • utility library
  • External – third parties libraries:
    • struts.jar
      • Struts web GUI framework
    • javax.servlet.jar
      • servlet API, used by Struts
    • log4j.jar
      • logging facility
    • commons-beanutils.jar
      • Apache commons bean utilities
    • jboss-aop-jdk50-client.jar
      • AOP facilities

Managing the actions

In the chapter Focusing on External Box design, we have created an action embedded into a component. Here we only develop the action part itself as this external action will be called from another component of the ConfiguratorUI.

HOW TO CREATE AN ACTION?

To develop external action, a class should be created that extends AjaxUpdateAction class and implements the inherited abstract method:

protectedabstractvoid doModelUpdate(HttpServletRequest request, ActionForm form);

The method receives the original HTTP request, as well as the form, which has been populated by the Struts framework – if such was configured for the action. The action contains the following code:

/**

*Aconstantrepresentingexternalactionparameterkey.

*/

privatestaticfinal String EXTERNAL_ACTION_PARAM_RESOURCE_NAME =

"resourceName";

/**

*{@inheritDoc}

*/

@Override

protectedvoid doModelUpdate(HttpServletRequest request, ActionForm form)

{

ConfiguratorUIService configUIService =

(ConfiguratorUIService)request.getSession()

.getAttribute(ConfiguratorUIService.CONFIGURATOR_UI_SERVICE);

String actionDataObjectId =

configUIService.getActionDataObjectId(request);

String resourceName =

request.getParameter(EXTERNAL_ACTION_PARAM_RESOURCE_NAME);

configUIService.addFrontEndMessage(

request,

FrontEndMessage.Type.DOMAIN_VALUE,

FrontEndMessage.Severity.INFO,

"externalAction.info",

"External action is called.",

new Object[] {actionDataObjectId, resourceName});

}

The ConfiguratorUIService is available in the session and can be extracted as shown in the code above. It provides functionality needed to external components in order to communicate with the Configurator UI application.

All external actions receive as a request parameter the selected object’s data ID (as string). It can be retrieved via the Configurator UI service’s method:

public String getActionDataObjectId(HttpServletRequest request)

Action parameters

An external action can be configured in the ConfiguratorUI.xml with action name and parameter pairs – param1=value1, param2=value2, etc. These parameters are available

in doModelUpdate() function of the action as request parameters in the HttpServletRequest under the same names as given in the configuration of the action. In such a way a parameter with

name resourceName is retrieved from the request and its value is added to the message. Then this message is printed in the information flyer of the application.

Warning: Since R8 version, this parameters must contains the moduleContext parameter.

This parameter is mandatory and permits to the UI to identify if action is a Configurator or a Catalog action. Pair parameterName/Value is built by the catalogUI/configuratorUI service in the controller.

HOW TO CONFIGURE AN ACTION?

The struts-config.xml file must be supplied. The XML for the external action example:

<?xml version="1.0" encoding="UTF-8" ?>

<struts-config>

<!-- ========== Form Bean Definitions ========================= -->

<!-- ========== Action Mapping Definitions ==================== -->

<action-mappings>

<action

path="/externalaction"

type="com.cameleon.demo.actions.SimpleExternalAction"

scope="request"

validate="false"

/>

</action-mappings>

</struts-config>

In this case the forms declaration section is empty. The <action-mapping> section configures the actions.

  • path – the URL which will be used to call the action;

    In the given example, the URL will be ‘/externalaction.do’ since the “do” postfix is the default one for Struts. This URL is the one that was used in the JSP of the selector – to generate the Ajax call to the action. It should correspond to the external action’s attribute – actionName in the Layout XML File.

    <externalActionactionName=”externalaction(resourceName=example.jpg)” ..>

    Note: The action name is converted to lower case.
    • type – the package qualified name of the action class
    • scope – where Struts should put the form on its creation and population with data;
    • validate – set to true if the validate method of the action associated with this mapping should be called;

Packaging and deploying the component

Note: The advanced external component is packaged and deployed in the same way as the basic external component: Packaging and deploying the component

The only difference with the basic component is the name of the pages folder under which the public resources of the component are located – this time the directory is cameleonUI.war/externalComponents/externalActionComponent.

Running the new component

The new external action can now be used in the Layout XML file.

There is an example of external action declaration. An external action is configured with the following declaration in the configuratorUI.xml.

<externalAction

actionName="externalAction(resourceName=example.jpg)"

alignment="left" resourceName="action.externalAction"

translationName="action.externalAction" url="" actionTarget="top">

<javascript>alert('External action javascript!')

</javascript>

</externalAction>

It can be added in <actionBox> or in <actionFlyer>. The attributes that characterize the external action are:

  • actionName – has the format externalActionName or externalActionName(param1=value1, param2=value2...).
  • actionTarget – possible values are blank|self|parent|top.
    • blank will open a new browser window
    • self will replace the current html page
    • parent will replace the html page it came from
    • top will load in the current browser by replacing anything within the browser such as a frameset
  • alignment – gives the position of the action in the action box. Possible values are: left|center|right
  • translationName – the translation name of the action
  • resourceName – an image icon that visualizes the action.
  • url – url of redirection, used if not empty when an user clicks on the external action

External action tag can contain <javascript> tag. The java script is added to the action’s configuration and is executed before the action is executed.

In the example, the external Action is inserted into the action box of the FormProperty boxes. After the external action is called the java script alert is shown, and then an information flyer is presented

with the following information.