Dynamic Attribute

Dynamic Attribute:

We all know that any attribute we define in item type will have particular tag called persistent type. Dynamic attribute is something where we get values as dynamic instead of database.

persistent type=”property”

In this case corresponding columns will created in database and the values will stored in database. so we call it as persistent attribute.

persistent type=”dynamic”

In such case no columns will created in the database and hence values will also not stored in database. so we call it as Non persistent or dynamic attribute.

if we define dynamic attribute , we need to mention the attribute handler for dynamic fields otherwise bean id will be generated automatically and we have to use the same bean id while defining spring for Dynamic attributehandlerclass .

Steps to create Dynamic attribute handler:

  1. In items.xml we need to define the persistent type as dynamic for the field you want as Dynamic and also attributehandler in the persistence tag.
<persistence type="dynamic" attributeHandler="shipmentHandler"/ >

2. Define class DynamicAttributehandler which extends abstract Dynamic attribute handler or implements attribute handler.

Ex:
public class CustomShipmentHandler extends AbstractDynamicAttributeHandler<Integer, OrderModel>
{
@Override
public Integer get(final OrderModel model)
{
//write your logic

3. Define the bean for this handler class and bean id should be same as attribute handler which we defined in items.xml.

Ex:
<bean id ="shipmentHandler" class="org.training.core.attributes.CustomShipmentHandler"/>

Go for build and update the system.

Leave a comment