The component
element executes a method within a component
or sets property and outputs values from a component to the output ModelMap
. It can also resolve a component or invoke a method on a component.
The component
element contains the following:
Attribute/Element | Description |
---|---|
| Identifies the Nucleus path of the component. |
| (Optional) Identifies the name of the method to be executed. Use only when invoking a method. |
| Provides a variable name that accesses the component’s properties. |
| Identifies the variable name that accesses the method invocation’s returned value. |
| This attribute defines the actor ID, and is used for actor ordering. |
| By default, all set-property values require session confirmation numbers. This property is set to |
| By default, all method calls require session confirmation numbers. This property is set to |
| This element defines actors that must be executed prior to the execution of the current actor. There can be multiple |
| This element defines actors that, if present, must be executed prior to the execution of the current actor. There can be multiple |
| This element defines each actor’s input. Actors can have multiple |
| This element defines each actor’s output. |
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.
, you must provide the
getOrderCount(String,String[])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,
method needs the interface class-names:
RepositoryItem, Map)
<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.
method, you would create the following:
filterInactiveSites (Collection<Site>)
<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 |
---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 did 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="paymentFroupFormHandler" 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 ATG 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.