The component element executes a method within a component, or sets properties and outputs values from a component to the output ModelMap.

The component element contains the following:

Attribute/Element

Description

name

Required. Identifies the Nucleus path of the component.

id

Required. This attribute defines the actor ID, and is used for actor ordering.

method

Identifies the name of the method to be executed. Use only when invoking a method.

component-var

Provides a variable name that accesses the component’s properties.

method-return-var

Identifies the variable name that accesses the method invocation’s returned value.

set-property-requires-session-confirmation

By default, all set-property values require session confirmation numbers. This property is set to true by default.

invoke-method-requires-session-confirmation

By default, all method calls require session confirmation numbers. This property is set to true by default.

depends

This element defines actors that must be executed prior to the execution of the current actor. There can be multiple depends elements associated with an actor.

depends-if-present

This element defines actors that, if present, must be executed prior to the execution of the current actor. There can be multiple depends-if-present elements associated with an actor

input

This element defines each actor’s input. Actors can have multiple input elements.

output

This element defines each actor’s output. Output elements create a map entry in a ModelMap. Actors can have multiple output elements.

Example: Resolving a Component

The following example resolves a component that sends output from the properties of the component to a ModelMap. In this example, the component class instance is saved in the shoppingCart variable of the ActorContext.

<component id="shoppingCart" name="/atg/commerce/ShoppingCart"
    component-var="shoppingCart" >
  <output name=orderId" name="orderId" value="${shoppingCart.last.id}"/ >
</component>

Note that you can reference a component without having to invoke a component actor. The following example shows how you would resolve the orderID component in-line. This works for components that are referenced only once; if you plan to reference the same component multiple times, it is best to define the variable, as in the above example:

<input name="ordered" value="${nucleus['/atg/userprofiling/
    ActiveCustomerProfile'].orderId}"/>
Example: Executing a Method

You can also use the component element to execute a method on a Nucleus component. The following example shows how the return value is stored in the orderStatus variable and stores the method return value into the ModelMap under the orderStatus key.

<component id="orderStatus" name="/atg/commerce/order/OrderServices"
    method="getOrderStatus" component-var="orderService"
    method-return-var="orderStatus">
  <input name="viewOrderId" value="${param.orderId}" />
  <output name="orderStatus" value="${orderStatus}" />
</component>
Example: Finding a Method using a String Array

You can also use the component element to find a method by providing a string array. For example, to find a method that contains a string array, such as atg.commerce.order.OrderLookupService.
getOrderCount(String,String[])
, you must provide the String and String[] class-names. In the following example, the String[] is passed in as [Ljava.lang.String; and passed to the getOrderCount method.

<component id="orderLookupService" name="/atg/commerce/order/OrderLookupService"
    method="getOrderCount" method-return-var="numberOfOrders">
  <input name="profile" class-name="java.lang.String"
      value="${profile.repositoryId}" />
  <input name="closedStates" class-name="[Ljava.lang.String;"
      value="$nucleus['/atg/commerce/order/OrderLookup'].closedStates" />
</component>
Example: Finding a Method Using an Interface

You can use the component element to find a method if the method has an interface signature. For example, the atg.commerce.pricing.PricingTools.priceOrderSubtotal(Order, Locale,
RepositoryItem, Map)
method needs the interface class-names:

<component id="pricingTools" name="/atg/commerce/pricing/PricingTools"
    method="priceOrderSubtotal">
  <input name="order" class-name="atg.commerce.order.Order" index="0"
      value="${nucleus['/atg/commerce/ShoppingCart'].current}"/>
  <input name="locale" class-name="java.util.Locale" index="1"
      value="${nucleus['/atg/dynamo/servlet/RequestLocale'].locale}"/>
  <input name="profile" class-name="atg.repository.RepositoryItem" index="2"
      value="${nucleus['/atg/userprofiling/Profile']}"/>
  <input name="parameters" class-name="java.util.Map" index="3" value="${null}"/>
</component>
Example: Finding a Method using Generics

If you are using a method that contains a generic class or interface, use the component element to provide the necessary type parameters. For example, to find the atg.multisite.SiteGroupManager.
filterInactiveSites (Collection<Site>)
method, you would create the following:

<component id="siteGroupManager" name="/atg/multisite/SiteGroupManager"
    method="filterInactiveSites" component-var="siteGroupManager "
    method-return-var="sites">
  <input name="sites" class-name="java.util.Collection"
      value="${objectParam.sites}" />
  <output id="sites" name="sites" value="${sites}" />
</component>
Example: Using Primitives When Executing Methods

The REST MVC framework accepts the use of primitive data types. The following example shows how a boolean primitive data type is identified using a primitive type name in class-name:

<component id="siteManager" name="/atg/multisite/SiteManager"
   method="getSitesByState" component-var="siteManager" method-return-var="sites">
  <input name="active" class-name="boolean" value="${param.active}" />
  <output id="sites" name="sites" value="${sites}" />
</component>
Example: Using Primitive Arrays When Executing Methods

You can use an array of primitive data types to return method information. The following example shows how a Boolean primitive array is used:

<component id="myComponent" name="/custom/MyComponent"
   method="getOrders" component-var="myComponent" method-return-var="orders">
  <input name="flags" class-name="[Z" value="${objectParam.flags}" />
  <output id="orders" name="orders" value="${orders}" />
</component>

Note that the following class-name values are used to identify primitive array types:

Primitive Data Array Type

Class-Name Value

char

[C For example, class-name="[C"

short

[S For example, class-name="[S"

double

[D For example, class-name="[D"

long

[J For example, class-name="[J"

boolean

[Z For example, class-name="[Z"

byte

[B For example, class-name="[B"

float

[F For example, class-name="[F"

int

[I For example, class-name="[I"

Example: Passing Multiple Arguments

To pass more than one argument into a method, you must specify the index attribute on the inputs so that the input arguments for the method are ordered. For complex object types, you may need to convert the string value to an object by specifying a PropertyEditor or TagConverter. Any registered property manager can be used to convert inputs into complex object types so that they may pass method parameters. The system attempts to coerce the input value to the correct type of object based on the method’s expected input type. If the method is overloaded, you may need to specify the PropertyEditor to disambiguate between the overloaded methods. Also, it is usually necessary to define a PropertyEditor for collections of complex objects since the type of objects contained in the collection cannot be determined at run time.

<component id="methodEx" name="/my/component/Example" method="doSomething"
    component-var="example" method-return-var="rtn">
  <!-Fictitious DateListPropertyEditor that converts pDateRange into a list of
     dates -->
  <input name="pDateRange" value="${param.dateRange}" index="0"
      property-editor="atg.nucleus.PropertyEditors.DateListPropertyEditor"/>
  <!-We do not need to specify the ProperyEditor but we could specify
       atg.nucleus.PropertyEditors.LocalePropertyEditor -->
  <input name="pLocale" value="${param.locale}" index="1"/>
</component>
Example: Setting Property Values

The following is an example of setting property values on a Nucleus component. The ComponentActor sets the listId property value and outputs the currentList property value:

<actor-chain-id=getCommerceIdentifierPaymentInfos">
  <component id="paymentGroupFormHandler"
      name="/atg/commerce/order/pruchase/PaymentGroupFormHandler
      component-var="paymentGroupFormHandler">
    <input name="listId" value="${param.listId}" priority="1000" />
    <output id="currentList" name="currentList"
        value="${paymentGroupFormHandler.currentList}" />
  </component>
</actor-chain>
Example: Disabling Component Actor Dynamo Session Confirmation Numbers

Important: The following information is for use within development environments only. Dynamo session confirmation numbers provide session security and must be enabled in production environments.

By default ComponentActors use Dynamo session confirmation numbers, _dynSessConf, for method calls and setting property values. However, session confirmation numbers are not required for calls such as outputting properties of a component, a JSPActor or a DropletActor. For detailed information on Dynamo Session Confirmation Numbers, refer to the Platform Programming Guide.

The following example shows how to disable session confirmation numbers for method calls:

<component id="orderStatus" name="/atg/commerce/order/OrderServices"
    method="getOrderStatus" component-var="orderService"
    method-return-var="orderStatus"
    invoke-method-requires-session-confirmation="false">
  <input name="viewOrderId" value="${param.orderId}"
      class-name="java.lang.String" />
  <output id="orderStatus" name="orderStatus" value="${orderStatus.state}" />
</component>

The following example shows how to disable set property values:

<component id="salesChannel" name="/atg/commerce/order/OrderServices"
    component-var="orderService"
       set-property-requires-session-confirmation="false">
  <input name="viewOrderId" value="contactCenter"
      class-name="java.lang.String" />
  <output id="orderStatus" name="salesChannel"
      value="${orderService.salesChannel} " />
</component>

Note that the /atg/dynamo/service/actor/Configuration.enforceSessionConfirmation flag can be used to disable this requirement during development. It is recommended that this flag is disabled only in your development environment.


Copyright © 1997, 2015 Oracle and/or its affiliates. All rights reserved. Legal Notices